diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 63d1b336..31b8533f 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -689,6 +689,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: @@ -735,9 +738,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) @@ -775,6 +782,18 @@ def fields2pelican( download_attachments(output_path, urls) +def is_pandoc2_installed(): + cmd = ['pandoc', '--version'] + try: + output = subprocess.check_output(cmd).decode('utf-8') + 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 "