nasg/pandoc.py
Peter Molnar fc2288c2fc - removed python markdown traces
- fixed gone_re php regexes
- better nav header layout
- follow page instead of direct RSS link
- logger in settings for nasg instead of direct logging
- prism.js only for articles with language code blocks
- added webmention.io webhook to email template
2018-08-08 09:42:42 +01:00

49 lines
1.4 KiB
Python

import subprocess
import logging
class Pandoc(str):
def __new__(cls, text):
# TODO: cache?
# import hashlib
# print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
""" Pandoc command line call with piped in- and output """
cmd = (
'pandoc',
'-o-',
'--from=markdown+%s' % (
'+'.join([
'footnotes',
'pipe_tables',
'strikeout',
#'superscript',
#'subscript',
'raw_html',
'definition_lists',
'backtick_code_blocks',
'fenced_code_attributes',
'shortcut_reference_links',
'lists_without_preceding_blankline',
'autolink_bare_uris',
])
),
'--to=html5',
'--quiet',
'--no-highlight'
)
p = subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate(input=text.encode())
if stderr:
logging.warning(
"Error during pandoc covert:\n\t%s\n\t%s",
cmd,
stderr
)
r = stdout.decode('utf-8').strip()
return str.__new__(cls, r)