This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/build/pandoc.py
2017-05-10 17:22:55 +01:00

33 lines
849 B
Python

import pypandoc
import os
from md_pdf.consts import CSL_DIR
import logging
logger = logging.getLogger(__file__)
def output_html(html, out_dir):
logger.info("Outputting HTML...")
with open(os.path.join(out_dir, 'output.html'), 'w') as f:
f.write(html)
def build_document(files_content, bibliography, context):
args = [
'-s',
]
filters = []
if bibliography is not None:
args += [
'--bibliography={}'.format(os.path.abspath(bibliography['references'])),
'--csl={}'.format(os.path.join(CSL_DIR, "{}.csl".format(bibliography['csl'])))
]
filters.append('pandoc-citeproc')
logger.info("Rendering Document...")
return pypandoc.convert_text(
files_content,
'html',
format='md',
extra_args=args,
filters=filters
)