From 5365a1cdb3ae57e92b89e7c2d8c0915bbeaf05c4 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 18 Apr 2018 23:10:34 +0200 Subject: [PATCH] PELICAN: pelican_import.py: add support for pelican-import -m asciidoc Signed-off-by: Tim Janik --- pelican/tools/pelican_import.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index bb3b8fc3..77226cd3 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -571,6 +571,29 @@ def build_header(title, date, author, categories, tags, slug, header += '\n' return header +def build_asciidoc_header(title, date, author, categories, tags, slug, + status=None, attachments=None): + """Build a header from a list of fields""" + + from docutils.utils import column_width + + header = '= %s\n' % title + if author: + header += '%s\n' % author + if date: + header += '%s\n' % date + if categories: + header += ':category: %s\n' % ', '.join(categories) + if tags: + header += ':tags: %s\n' % ', '.join(tags) + if slug: + header += ':slug: %s\n' % slug + if status: + header += ':status: %s\n' % status + if attachments: + header += ':attachments: %s\n' % ', '.join(attachments) + header += '\n' + return header def build_markdown_header(title, date, author, categories, tags, slug, status=None, attachments=None): @@ -595,7 +618,9 @@ def build_markdown_header(title, date, author, categories, tags, def get_ext(out_markup, in_markup='html'): - if in_markup == 'markdown' or out_markup == 'markdown': + if out_markup == 'asciidoc': + ext = '.adoc' + elif in_markup == 'markdown' or out_markup == 'markdown': ext = '.md' else: ext = '.rst' @@ -775,7 +800,10 @@ def fields2pelican( links = None ext = get_ext(out_markup, in_markup) - if ext == '.md': + if ext == '.adoc': + header = build_asciidoc_header(title, date, author, categories, + tags, slug, status, attached_files) + elif ext == '.md': header = build_markdown_header( title, date, author, categories, tags, slug, status, links.values() if links else None)