Get rid of pypandoc module, use only pandoc executable

This commit is contained in:
Andrei Astafev 2019-04-20 10:54:35 +03:00
parent cf22eb9e86
commit 6999990a60

View File

@ -18,8 +18,11 @@ PANDOC_EXPORT_ARTICLES True (default) if you want to export articles, False
else. else.
PANDOC_EXPORT_PAGES True (default) if you want to export pages, False else. PANDOC_EXPORT_PAGES True (default) if you want to export pages, False else.
Important note: this plugin requires Pandoc and pypandoc to be installed on PANDOC_MARKDOWN_EXTENSIONS a list with Pandoc's markdown extensions
your system to work! PANDOC_EXECUTABLE path to pandoc executable
PANDOC_EXTRA_OPTIONS extra options to pandoc executable
Important note: this plugin requires Pandoc to be installed on your system to work!
""" """
@ -31,9 +34,7 @@ import logging
from pelican import signals from pelican import signals
from pelican.generators import Generator from pelican.generators import Generator
# TODO: it could be great to not depend on an external module for such a basic from subprocess import check_call
# work.
import pypandoc
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -93,6 +94,10 @@ class PandocGenerator(Generator):
:type content: pelican.contents.Content :type content: pelican.contents.Content
""" """
if self.settings.get('PDF_PROCESSOR', False) == False:
return
try: try:
from_format = self.guess_format(content) from_format = self.guess_format(content)
except KeyError: except KeyError:
@ -120,22 +125,17 @@ class PandocGenerator(Generator):
# Pandoc don't take "pdf" as an output value. Use latex instead. # Pandoc don't take "pdf" as an output value. Use latex instead.
to_format = 'latex' if to_format == 'pdf' else to_format to_format = 'latex' if to_format == 'pdf' else to_format
# Use the same format as Pelican (paticularly for metadata!) # Use the same format as Pelican (paticularly for metadata!)
from_format = 'markdown_mmd' if from_format == 'md'\ if from_format == 'md':
else from_format from_format = 'markdown' + \
''.join(self.settings.get('PANDOC_MARKDOWN_EXTENSIONS', []))
# Here is the magic! # Here is the magic!
# TODO: support extra_args extending (it could be useful to use # TODO: support extra_args extending (it could be useful to use
# specific Pandoc template). # specific Pandoc template).
pypandoc.convert( check_call([self.settings.get('PANDOC_EXECUTABLE', 'pandoc')] +
source=content.source_path, self.settings.get('PANDOC_EXTRA_OPTIONS', []) +
to=to_format, ['-f', from_format, '-t', to_format ] +
format=from_format, ['--standalone', '-o', filepath, content.source_path])
extra_args=(
'--smart',
'--standalone',
'-o', filepath,
)
)
logger.info("[ok] writing {filepath}".format( logger.info("[ok] writing {filepath}".format(
filepath=filepath filepath=filepath