Compare commits
No commits in common. "3d88725c97847914a1aae4954d96b68c0ef036f2" and "ea76f5e558c078143b23d20c12d7c5da073efa06" have entirely different histories.
3d88725c97
...
ea76f5e558
@ -4,7 +4,7 @@ import subprocess
|
||||
from pelican import signals
|
||||
from pelican.readers import BaseReader
|
||||
from pelican.utils import pelican_open
|
||||
import os
|
||||
|
||||
|
||||
try:
|
||||
import yaml
|
||||
@ -40,9 +40,6 @@ class PandocReader(BaseReader):
|
||||
name, value = k.lower(), parsed[k]
|
||||
metadata[name] = self.process_metadata(name, value)
|
||||
|
||||
if (not 'summary' in metadata) or (metadata['summary'] is None):
|
||||
metadata['summary'] = ''
|
||||
|
||||
# Return the text entirely.
|
||||
content = "\n".join(text)
|
||||
|
||||
@ -64,51 +61,34 @@ class PandocReader(BaseReader):
|
||||
|
||||
metadata, content = self._get_meta_and_content(text)
|
||||
|
||||
filters = self.settings.get('PANDOC_FILTERS', [])
|
||||
extra_args = self.settings.get('PANDOC_ARGS', [])
|
||||
extensions = self.settings.get('PANDOC_EXTENSIONS', '')
|
||||
if isinstance(extensions, list):
|
||||
extensions = ''.join(extensions)
|
||||
|
||||
pandoc_cmd = ["pandoc", "--from=markdown" + extensions, "--to=html5"]
|
||||
for filt in filters:
|
||||
pandoc_cmd.extend(["--filter", filt])
|
||||
pandoc_cmd.extend(extra_args)
|
||||
|
||||
bib_dir = self.settings.get('PANDOC_BIBDIR', '')
|
||||
bib_header = self.settings.get('PANDOC_BIBHEADER', None)
|
||||
if "bibliography" in metadata.keys():
|
||||
bib_file = os.path.join(bib_dir, metadata['bibliography'])
|
||||
if not os.path.exists(bib_file):
|
||||
raise FileNotFoundError(bib_file)
|
||||
bib_args = ['--bibliography={}'.format(bib_file)]
|
||||
extra_args = extra_args + ['--bibliography={}'.format(bib_file)]
|
||||
|
||||
if bib_header is not None:
|
||||
bib_args = bib_args + [
|
||||
extra_args = extra_args + [
|
||||
'--metadata=reference-section-title="{}"'.format(
|
||||
bib_header)]
|
||||
pandoc_cmd.extend(bib_args)
|
||||
|
||||
if "toc" in metadata.keys():
|
||||
if metadata['toc'] == True:
|
||||
pandoc_cmd.extend(['--toc'])
|
||||
proc = subprocess.Popen(pandoc_cmd,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE)
|
||||
|
||||
proc = subprocess.Popen(
|
||||
pandoc_cmd,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
|
||||
output, err = proc.communicate(content.encode('utf-8'))
|
||||
output = proc.communicate(content.encode('utf-8'))[0].decode('utf-8')
|
||||
status = proc.wait()
|
||||
output, err = output.decode('utf-8'), err.decode('utf-8')
|
||||
if status > 0:
|
||||
logging.warning(output + err)
|
||||
|
||||
# Make sure we don't lose Pelican template parameters.
|
||||
# Just in case, let's make sure we don't lose Pelican template
|
||||
# parameters.
|
||||
output = output.replace('%7Battach%7D', '{attach}')\
|
||||
.replace('%7Bfilename%7D', '{filename}')\
|
||||
.replace('%7Bstatic%7D', '{static}')\
|
||||
.replace('%7Btag%7D', '{tag}')\
|
||||
.replace('%7Bcategory%7D', '{category}')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user