diff --git a/md_pdf/build/__init__.py b/md_pdf/build/__init__.py index 141f134..14fbcf5 100644 --- a/md_pdf/build/__init__.py +++ b/md_pdf/build/__init__.py @@ -7,7 +7,7 @@ import os def build(config): data = read_files(os.path.abspath(config.input)) - doc = build_document(data, getattr(config, 'bibliography', None)) + doc = build_document(data, getattr(config, 'bibliography', None), getattr(config, 'context', None)) if 'html' in config.output_formats: output_html(doc, os.path.abspath(config.output_dir)) if 'pdf' in config.output_formats: diff --git a/md_pdf/build/pandoc.py b/md_pdf/build/pandoc.py index 44b825f..4541647 100644 --- a/md_pdf/build/pandoc.py +++ b/md_pdf/build/pandoc.py @@ -2,6 +2,7 @@ import pypandoc from bs4 import BeautifulSoup import os from md_pdf.consts import PROJECT_DIR, CSL_DIR +from jinja2 import Template CSL_FILE = os.path.join(PROJECT_DIR, 'assets', 'harverd.csl') @@ -22,7 +23,12 @@ def output_html(html, out_dir): f.write(html) -def build_document(files_content, bibliography): +def parse_template(html, context): + template = Template(html) + return template.render(context) + + +def build_document(files_content, bibliography, context): args = [ '-s', ] @@ -34,12 +40,12 @@ def build_document(files_content, bibliography): ] filters.append('pandoc-citeproc') - html = pypandoc.convert_text( + html = fix_references_title(pypandoc.convert_text( files_content, 'html', format='md', extra_args=args, filters=filters - ) + )) - return fix_references_title(html) + return parse_template(html, context.toDict()) diff --git a/md_pdf/build/pdf.py b/md_pdf/build/pdf.py index 27df804..8cd3781 100644 --- a/md_pdf/build/pdf.py +++ b/md_pdf/build/pdf.py @@ -20,7 +20,6 @@ PDF_OPTIONS = { "footer-html": FOOTER_FILE, "footer-spacing": 5, "header-spacing": 5, - } diff --git a/test-files/mdp.yml b/test-files/mdp.yml index 6e8f7f4..6118dd9 100644 --- a/test-files/mdp.yml +++ b/test-files/mdp.yml @@ -8,3 +8,5 @@ bibliography: csl: apa context: foo: bar + bar: foo +title: test