From dacc09212509b9ee1bfe3a5ec115807931d0d9cc Mon Sep 17 00:00:00 2001 From: David Wilemski Date: Sat, 10 Feb 2018 20:54:28 -0800 Subject: [PATCH 1/2] Make pelican-import support pandoc2. Fixes #2255 --- pelican/tools/pelican_import.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 8d252536..ab7e4ae6 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -682,6 +682,9 @@ def fields2pelican( dircat=False, strip_raw=False, disable_slugs=False, dirpage=False, filename_template=None, filter_author=None, wp_custpost=False, wp_attach=False, attachments=None): + + pandoc2 = is_pandoc2_installed() + for (title, content, filename, date, author, categories, tags, status, kind, in_markup) in fields: if filter_author and filter_author != author: @@ -727,9 +730,13 @@ def fields2pelican( fp.write(new_content) - parse_raw = '--parse-raw' if not strip_raw else '' - cmd = ('pandoc --normalize {0} --from=html' - ' --to={1} -o "{2}" "{3}"') + parse_raw = '--parse-raw' if not strip_raw and not pandoc2 else '' + if pandoc2: + cmd = ('pandoc {0} --from=html ' + '--to=gfm+raw_html -o "{2}" "{3}"') + else: + cmd = ('pandoc --normalize {0} --from=html' + ' --to={1} -o "{2}" "{3}"') cmd = cmd.format(parse_raw, out_markup, out_filename, html_filename) @@ -764,6 +771,18 @@ def fields2pelican( download_attachments(output_path, urls) +def is_pandoc2_installed(): + cmd = ['pandoc', '--version'] + try: + output = subprocess.check_output(cmd) + except subprocess.CalledProcessError: + return None + + if re.search(r'^pandoc 2\..+$', output, re.M): + return True + return False + + def main(): parser = argparse.ArgumentParser( description="Transform feed, WordPress, Tumblr, Dotclear, or " From 7ab2d1fddf05b577d715a16a8d63e470c12aed6b Mon Sep 17 00:00:00 2001 From: David Wilemski Date: Sat, 10 Feb 2018 21:17:14 -0800 Subject: [PATCH 2/2] Decode pandoc --version output into a string --- pelican/tools/pelican_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index ab7e4ae6..0721666a 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -774,7 +774,7 @@ def fields2pelican( def is_pandoc2_installed(): cmd = ['pandoc', '--version'] try: - output = subprocess.check_output(cmd) + output = subprocess.check_output(cmd).decode('utf-8') except subprocess.CalledProcessError: return None