Compare commits
10 Commits
ea76f5e558
...
3d88725c97
Author | SHA1 | Date | |
---|---|---|---|
3d88725c97 | |||
407b02f1fb | |||
e88d0482d5 | |||
38cad81050 | |||
2ecccea48a | |||
a1cc436b6e | |||
|
9d5cb7f790 | ||
|
860c63023c | ||
|
6fe6277a25 | ||
|
2fdb5b20b2 |
@ -4,7 +4,7 @@ import subprocess
|
|||||||
from pelican import signals
|
from pelican import signals
|
||||||
from pelican.readers import BaseReader
|
from pelican.readers import BaseReader
|
||||||
from pelican.utils import pelican_open
|
from pelican.utils import pelican_open
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
@ -40,6 +40,9 @@ class PandocReader(BaseReader):
|
|||||||
name, value = k.lower(), parsed[k]
|
name, value = k.lower(), parsed[k]
|
||||||
metadata[name] = self.process_metadata(name, value)
|
metadata[name] = self.process_metadata(name, value)
|
||||||
|
|
||||||
|
if (not 'summary' in metadata) or (metadata['summary'] is None):
|
||||||
|
metadata['summary'] = ''
|
||||||
|
|
||||||
# Return the text entirely.
|
# Return the text entirely.
|
||||||
content = "\n".join(text)
|
content = "\n".join(text)
|
||||||
|
|
||||||
@ -61,34 +64,51 @@ class PandocReader(BaseReader):
|
|||||||
|
|
||||||
metadata, content = self._get_meta_and_content(text)
|
metadata, content = self._get_meta_and_content(text)
|
||||||
|
|
||||||
|
filters = self.settings.get('PANDOC_FILTERS', [])
|
||||||
extra_args = self.settings.get('PANDOC_ARGS', [])
|
extra_args = self.settings.get('PANDOC_ARGS', [])
|
||||||
extensions = self.settings.get('PANDOC_EXTENSIONS', '')
|
extensions = self.settings.get('PANDOC_EXTENSIONS', '')
|
||||||
if isinstance(extensions, list):
|
if isinstance(extensions, list):
|
||||||
extensions = ''.join(extensions)
|
extensions = ''.join(extensions)
|
||||||
|
|
||||||
pandoc_cmd = ["pandoc", "--from=markdown" + extensions, "--to=html5"]
|
pandoc_cmd = ["pandoc", "--from=markdown" + extensions, "--to=html5"]
|
||||||
|
for filt in filters:
|
||||||
|
pandoc_cmd.extend(["--filter", filt])
|
||||||
pandoc_cmd.extend(extra_args)
|
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():
|
if "bibliography" in metadata.keys():
|
||||||
bib_file = os.path.join(bib_dir, metadata['bibliography'])
|
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:
|
if bib_header is not None:
|
||||||
extra_args = extra_args + [
|
bib_args = bib_args + [
|
||||||
'--metadata=reference-section-title="{}"'.format(
|
'--metadata=reference-section-title="{}"'.format(
|
||||||
bib_header)]
|
bib_header)]
|
||||||
|
pandoc_cmd.extend(bib_args)
|
||||||
|
|
||||||
proc = subprocess.Popen(pandoc_cmd,
|
if "toc" in metadata.keys():
|
||||||
|
if metadata['toc'] == True:
|
||||||
|
pandoc_cmd.extend(['--toc'])
|
||||||
|
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
pandoc_cmd,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE)
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE)
|
||||||
|
|
||||||
output = proc.communicate(content.encode('utf-8'))[0].decode('utf-8')
|
output, err = proc.communicate(content.encode('utf-8'))
|
||||||
status = proc.wait()
|
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
|
# Make sure we don't lose Pelican template parameters.
|
||||||
# parameters.
|
|
||||||
output = output.replace('%7Battach%7D', '{attach}')\
|
output = output.replace('%7Battach%7D', '{attach}')\
|
||||||
.replace('%7Bfilename%7D', '{filename}')\
|
.replace('%7Bfilename%7D', '{filename}')\
|
||||||
|
.replace('%7Bstatic%7D', '{static}')\
|
||||||
.replace('%7Btag%7D', '{tag}')\
|
.replace('%7Btag%7D', '{tag}')\
|
||||||
.replace('%7Bcategory%7D', '{category}')
|
.replace('%7Bcategory%7D', '{category}')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user