Compare commits

...

10 Commits

Author SHA1 Message Date
3d88725c97 Allow empty summary 2019-04-25 14:52:57 +03:00
407b02f1fb Merge branch 'fix-bib' 2019-04-25 14:51:30 +03:00
e88d0482d5 Merge branch 'fix' 2019-04-25 14:51:23 +03:00
38cad81050 Create table of contents if toc metadata key is set 2019-04-25 14:46:21 +03:00
2ecccea48a Fix bibliography arguments 2019-04-25 14:44:06 +03:00
a1cc436b6e Remove unneeded code 2019-04-25 14:40:00 +03:00
Dan MacKinlay
9d5cb7f790 missing {static} mangling 2019-03-08 15:27:32 +11:00
Dan MacKinlay
860c63023c diagnostics on pandoc failure 2019-02-24 12:51:56 +11:00
Dan MacKinlay
6fe6277a25 attempt to enable bibligraphy but founder in relative file paths 2019-02-23 16:14:24 +11:00
Dan MacKinlay
2fdb5b20b2 perfucntory attempt to handle bibliography 2019-02-22 21:02:27 +11:00

View File

@ -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,6 +40,9 @@ 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)
@ -61,34 +64,51 @@ 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'])
extra_args = extra_args + ['--bibliography={}'.format(bib_file)]
if not os.path.exists(bib_file):
raise FileNotFoundError(bib_file)
bib_args = ['--bibliography={}'.format(bib_file)]
if bib_header is not None:
extra_args = extra_args + [
bib_args = bib_args + [
'--metadata=reference-section-title="{}"'.format(
bib_header)]
pandoc_cmd.extend(bib_args)
proc = subprocess.Popen(pandoc_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
if "toc" in metadata.keys():
if metadata['toc'] == True:
pandoc_cmd.extend(['--toc'])
output = proc.communicate(content.encode('utf-8'))[0].decode('utf-8')
proc = subprocess.Popen(
pandoc_cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output, err = proc.communicate(content.encode('utf-8'))
status = proc.wait()
output, err = output.decode('utf-8'), err.decode('utf-8')
if status > 0:
logging.warning(output + err)
# Just in case, let's make sure we don't lose Pelican template
# parameters.
# 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}')