diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-09-18 14:43:55 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-09-18 14:43:55 +0100 |
commit | ec0200c5cb574a32442c8aaeb0860a49fd962cb0 (patch) | |
tree | 5eb6925447f7e8b64ab817ed95c692c9385c1332 | |
parent | 5d023ad5bc648c9ed91d6860f6f706331542bfe5 (diff) | |
download | subplot-ec0200c5cb574a32442c8aaeb0860a49fd962cb0.tar.gz |
pandoc: Add support for --citeproc
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/doc.rs | 3 | ||||
-rw-r--r-- | src/policy.rs | 24 |
2 files changed, 25 insertions, 2 deletions
@@ -159,8 +159,7 @@ impl<'a> Document { pandoc.set_output(pandoc::OutputKind::Pipe); // Add external Pandoc filters. - let citeproc = std::path::Path::new("pandoc-citeproc"); - pandoc.add_option(pandoc::PandocOption::Filter(citeproc.to_path_buf())); + crate::policy::add_citeproc(&mut pandoc); event!(Level::TRACE, ?filename, "Invoking Pandoc to parse document"); let output = match pandoc.execute()? { diff --git a/src/policy.rs b/src/policy.rs index e24bf8f..00a18d3 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -1,5 +1,8 @@ use std::path::{Component, Path, PathBuf}; +use pandoc::{InputFormat, InputKind, OutputFormat, OutputKind, Pandoc, PandocOption}; +use tracing::{event, instrument, Level}; + /// Get the base directory given the name of the markdown file. /// /// All relative filename, such as bindings files, are resolved @@ -14,3 +17,24 @@ pub fn get_basedir_from(filename: &Path) -> PathBuf { Some(x) => x.to_path_buf(), } } + +/// Add 'citeproc' to a Pandoc instance. +/// +/// This attempts to determine if `--citeproc` or `--filter pandoc-citeproc` +/// is needed, and then does that specific thing. +#[instrument(skip(pandoc))] +pub fn add_citeproc(pandoc: &mut Pandoc) { + let mut guesser = Pandoc::new(); + guesser.set_input(InputKind::Pipe("".to_string())); + guesser.set_input_format(InputFormat::Markdown, vec![]); + guesser.set_output_format(OutputFormat::Markdown, vec![]); + guesser.set_output(OutputKind::Pipe); + guesser.add_option(PandocOption::Citeproc); + if guesser.execute().is_ok() { + event!(Level::TRACE, "Discovered --citeproc"); + pandoc.add_option(PandocOption::Citeproc); + } else { + event!(Level::TRACE, "Discovered --filter pandoc-citeproc"); + pandoc.add_option(PandocOption::Filter("pandoc-citeproc".into())); + } +} |