From 82b5b93128773fcf8ad36cf94b73f7dd02a6e9af Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 29 Mar 2017 19:32:15 +0100 Subject: [PATCH] Allow custom bibliographies --- md_pdf/build/__init__.py | 4 +++- md_pdf/build/pandoc.py | 2 +- md_pdf/config/validate.py | 9 +++++++++ test-files/mdp.yml | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/md_pdf/build/__init__.py b/md_pdf/build/__init__.py index 1be55e1..3a753ad 100644 --- a/md_pdf/build/__init__.py +++ b/md_pdf/build/__init__.py @@ -8,7 +8,9 @@ import os def build(config): data = read_files(os.path.abspath(config.input)) - doc = build_document(data, os.path.join(WORKING_DIR, 'bib.yaml')) + doc = build_document(data, + os.path.abspath(config.bibliography) if 'bibliography' in config else 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 dc42a12..c7e4f63 100644 --- a/md_pdf/build/pandoc.py +++ b/md_pdf/build/pandoc.py @@ -21,7 +21,7 @@ def output_html(html, out_dir): f.write(html) -def build_document(files_content, bibliography): +def build_document(files_content, bibliography=None): args = [ '-s', ] diff --git a/md_pdf/config/validate.py b/md_pdf/config/validate.py index 9350e20..0459ca1 100644 --- a/md_pdf/config/validate.py +++ b/md_pdf/config/validate.py @@ -26,8 +26,17 @@ def test_output(config): raise ConfigValidationException("Invalid output formats provided: '{}'".format(", ".join(invalid_formats))) +def validate_bibliography(config): + if 'bibliography' not in config: + return + abs_bibliography = os.path.abspath(config.bibliography) + if not os.path.isfile(abs_bibliography): + raise ConfigValidationException("Invalid bibliography path: '{}'".format(abs_bibliography)) + + def validate_config(config): check_required_keys(config) test_output(config) + validate_bibliography(config) diff --git a/test-files/mdp.yml b/test-files/mdp.yml index dce2520..c7ddace 100644 --- a/test-files/mdp.yml +++ b/test-files/mdp.yml @@ -3,3 +3,4 @@ output_formats: - html - pdf output_dir: out/ +bibliography: bib.yaml