Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parameter PANDOC_EXEC #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A pandoc [markdown] reader plugin for [pelican]
Requirements
------------

- [pandoc] in $PATH
- [pandoc], ideally in $PATH but this is not mandatory.


Installation
Expand Down Expand Up @@ -37,6 +37,15 @@ PANDOC_EXTENSIONS parameter.
'-citations'
]

In case [pandoc] is not in $PATH it is possible to provide the full path:

PANDOC_EXEC = '/usr/local/bin/pandoc'

This parameter can also be used to call a variant of [pandoc] such as [scholdoc]:

PANDOC_EXEC = 'scholdoc'


Contributing
------------

Expand All @@ -50,3 +59,4 @@ Contributing
[markdown]: http://daringfireball.net/projects/markdown/
[pandoc]: http://johnmacfarlane.net/pandoc/
[pelican]: http://getpelican.com
[scholdoc]: http://scholdoc.scholarlymarkdown.com/
10 changes: 7 additions & 3 deletions pandoc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pelican.readers import BaseReader
from pelican.utils import pelican_open


class PandocReader(BaseReader):
enabled = True
file_extensions = ['md', 'markdown', 'mkd', 'mdown']
Expand All @@ -22,16 +23,17 @@ def read(self, filename):
break

extra_args = self.settings.get('PANDOC_ARGS', [])
executable = self.settings.get('PANDOC_EXEC', 'pandoc')
extensions = self.settings.get('PANDOC_EXTENSIONS', '')
if isinstance(extensions, list):
extensions = ''.join(extensions)

pandoc_cmd = ["pandoc", "--from=markdown" + extensions, "--to=html5"]
pandoc_cmd = [executable, "--from=markdown" + extensions, "--to=html5"]
pandoc_cmd.extend(extra_args)

proc = subprocess.Popen(pandoc_cmd,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE)
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)

output = proc.communicate(content.encode('utf-8'))[0].decode('utf-8')
status = proc.wait()
Expand All @@ -40,9 +42,11 @@ def read(self, filename):

return output, metadata


def add_reader(readers):
for ext in PandocReader.file_extensions:
readers.reader_classes[ext] = PandocReader


def register():
signals.readers_init.connect(add_reader)