diff --git a/md_pdf/build/__init__.py b/md_pdf/build/__init__.py index 3a753ad..5a5823f 100644 --- a/md_pdf/build/__init__.py +++ b/md_pdf/build/__init__.py @@ -8,9 +8,7 @@ import os def build(config): data = read_files(os.path.abspath(config.input)) - doc = build_document(data, - os.path.abspath(config.bibliography) if 'bibliography' in config else None - ) + doc = build_document(data, getattr(config, 'bibliography', 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 c7e4f63..2853457 100644 --- a/md_pdf/build/pandoc.py +++ b/md_pdf/build/pandoc.py @@ -1,7 +1,7 @@ import pypandoc from bs4 import BeautifulSoup -import os.path -from md_pdf.consts import PROJECT_DIR +import os +from md_pdf.consts import PROJECT_DIR, CSL_DIR CSL_FILE = os.path.join(PROJECT_DIR, 'assets', 'harverd.csl') @@ -21,15 +21,15 @@ def output_html(html, out_dir): f.write(html) -def build_document(files_content, bibliography=None): +def build_document(files_content, bibliography): args = [ '-s', ] filters = [] if bibliography is not None: args += [ - '--bibliography={}'.format(bibliography), - '--csl={}'.format(CSL_FILE) + '--bibliography={}'.format(os.path.abspath(bibliography.references)), + '--csl={}'.format(os.path.join(CSL_DIR, "{}.csl".format(bibliography.csl))) ] filters.append('pandoc-citeproc') diff --git a/md_pdf/config/validate.py b/md_pdf/config/validate.py index 0459ca1..97a55b5 100644 --- a/md_pdf/config/validate.py +++ b/md_pdf/config/validate.py @@ -1,4 +1,5 @@ from md_pdf.exceptions import ConfigValidationException +from md_pdf.consts import CSL_DIR import os @@ -29,9 +30,15 @@ def test_output(config): def validate_bibliography(config): if 'bibliography' not in config: return - abs_bibliography = os.path.abspath(config.bibliography) + if 'references' not in config.bibliography: + raise ConfigValidationException("Missing References Path") + + abs_bibliography = os.path.abspath(config.bibliography.references) if not os.path.isfile(abs_bibliography): raise ConfigValidationException("Invalid bibliography path: '{}'".format(abs_bibliography)) + if 'csl' in config.bibliography: + if not os.path.isfile(os.path.join(CSL_DIR, "{}.csl".format(config.bibliography.csl))): + raise ConfigValidationException("Could not find CSL '{}'".format(config.bibliography.csl)) def validate_config(config): diff --git a/test-files/mdp.yml b/test-files/mdp.yml index c7ddace..63e1ac9 100644 --- a/test-files/mdp.yml +++ b/test-files/mdp.yml @@ -3,4 +3,6 @@ output_formats: - html - pdf output_dir: out/ -bibliography: bib.yaml +bibliography: + references: bib.yaml + csl: apa