# HG changeset patch # User gibus # Date 1337856519 -7200 # Node ID b6e443be2a9b60ad5604905d90ff2f90cda03929 # Parent d5d3bcd26a0ba1d5588887b444a14db727e90718 Takes into account various releases of pandoc. diff -r d5d3bcd26a0b -r b6e443be2a9b src/cm/converters/abi_converters.py --- a/src/cm/converters/abi_converters.py Thu May 24 12:46:50 2012 +0200 +++ b/src/cm/converters/abi_converters.py Thu May 24 12:48:39 2012 +0200 @@ -100,7 +100,7 @@ type = TYPES_OUT.get( type or os.path.splitext(out_file)[1][1:], 'txt') - # do the coversion + # do the conversion self._perform_conversion(in_file, out_file, type) # return a byte string if no out_file is specified diff -r d5d3bcd26a0b -r b6e443be2a9b src/cm/converters/pandoc_converters.py --- a/src/cm/converters/pandoc_converters.py Thu May 24 12:46:50 2012 +0200 +++ b/src/cm/converters/pandoc_converters.py Thu May 24 12:48:39 2012 +0200 @@ -13,24 +13,32 @@ from cm.utils.string_utils import to_unicode from xml.dom.minidom import parseString import re +from distutils.version import LooseVersion PANDOC_BIN = "pandoc" -PANDOC_OPTIONS = " --sanitize-html --email-obfuscation=none " +import commands +PANDOC_VERSION = commands.getstatusoutput(PANDOC_BIN + " -v|head -n 1|awk '{print $2;}'")[1] +if LooseVersion(PANDOC_VERSION) < '1.8': + PANDOC_OPTIONS = " --sanitize-html --email-obfuscation=none " +else: + PANDOC_OPTIONS = " --email-obfuscation=none " + PANDOC_OPTIONS_RAW = " -R --email-obfuscation=none " -MARKDOWN2PDF_BIN = "markdown2pdf" +if LooseVersion(PANDOC_VERSION) < '1.9': + MARKDOWN2PDF_BIN = "markdown2pdf" +else: + MARKDOWN2PDF_BIN = None # make sure binaries are available from cm.utils.system import bin_search bin_search(PANDOC_BIN) -bin_search(MARKDOWN2PDF_BIN) +if MARKDOWN2PDF_BIN: + bin_search(MARKDOWN2PDF_BIN) # pandoc capabilities INPUT_FORMATS = ['native', 'markdown', 'rst', 'html', 'latex'] -OUTPUT_FORMATS = ['native', 'html', 's5', 'docbook', 'opendocument', 'odt', 'latex', 'context', 'texinfo', 'man', 'markdown', 'rst', 'mediawiki', 'rtf'] - -# add pdf output using markdown2pdf -OUTPUT_FORMATS.append('pdf') +OUTPUT_FORMATS = ['native', 'html', 's5', 'docbook', 'opendocument', 'odt', 'latex', 'context', 'texinfo', 'man', 'markdown', 'rst', 'mediawiki', 'rtf', 'pdf'] # input formats CHOICES_INPUT_FORMATS = [(f, f) for f in ['markdown', 'rst', 'html']] @@ -55,7 +63,7 @@ # tidy fails ... try pandoc anyway... content = to_unicode(content) # if to_format is pdf: use markdown2pdf - if to_format == 'pdf': + if MARKDOWN2PDF_BIN and to_format == 'pdf': if from_format != 'markdown': content = pandoc_convert(content, from_format, 'markdown', True) return pandoc_markdown2pdf(content) @@ -191,7 +199,11 @@ # temp file input_file, input_temp_name = get_filetemp('w', 'input') - output_temp_fp, output_temp_name = get_filetemp('r', 'output') + # For some reason when pandoc > 1.9 converts to PDF, '-t' shouldn't be used but output file name extension has to be '.pdf' + if to_format != 'pdf': + output_temp_fp, output_temp_name = get_filetemp('r', 'output') + else: + output_temp_fp, output_temp_name = get_filetemp('r', 'output.pdf') output_temp_fp.close() error_temp_fp, error_temp_name = get_filetemp('w', 'err') @@ -231,7 +243,8 @@ if full: cmd_args += ' -s ' cmd_args += ' -f %s ' % from_format - cmd_args += ' -t %s ' % to_format + if to_format != 'pdf': + cmd_args += ' -t %s ' % to_format cmd_args += ' %s ' % input_temp_name cmd = PANDOC_BIN + ' ' + cmd_args