From 6e133b25e02edba228c488a4239334885b5ebc85 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 28 Nov 2021 16:37:04 +0100 Subject: config: add way for setting pandoc default options and update Cargo.lock --- src/build.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/build.rs') diff --git a/src/build.rs b/src/build.rs index 1c12476..cf34e2f 100644 --- a/src/build.rs +++ b/src/build.rs @@ -14,12 +14,22 @@ const HTML_TEMPLATE: &str = include_str!("../res/template.html"); pub fn do_build(config: &crate::config::Config) -> Result<()> { let tmpdir = tempfile::tempdir().wrap_err("Could not create temporary directory")?; - debug!("Created temporary directory at: '{}'", tmpdir.path().display()); + debug!( + "Created temporary directory at: '{}'", + tmpdir.path().display() + ); + let template_path = tmpdir.path().join("template.html"); trace!("Writing HTML template to: '{}'", template_path.display()); std::fs::write(&template_path, HTML_TEMPLATE) .wrap_err("Could not save HTML template in temporary directory")?; + let defaults_path = tmpdir.path().join("defaults.yaml"); + debug!("Generating file: '{}'", defaults_path.display()); + let defaults = + std::fs::File::create(&defaults_path).wrap_err("Could not create defaults.yaml")?; + serde_json::to_writer(defaults, &config.pandoc).wrap_err("Could not create defaults.yaml")?; + let source_root = Path::new(&config.book.summary) .parent() .expect("Summary has no parent"); @@ -99,6 +109,7 @@ pub fn do_build(config: &crate::config::Config) -> Result<()> { .set_output_format(pandoc::OutputFormat::Html5, vec![]) .add_options(&[ pandoc::PandocOption::Css(style_path.to_string()), + pandoc::PandocOption::Defaults(defaults_path.clone()), pandoc::PandocOption::SectionDivs, pandoc::PandocOption::Standalone, pandoc::PandocOption::Template(template_path.clone()), -- cgit v1.2.3