summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-18 13:57:42 +0000
committerLars Wirzenius <liw@liw.fi>2021-09-18 13:57:42 +0000
commitf1c2110154cb153301f22906e793460e7236fbb8 (patch)
tree5eb6925447f7e8b64ab817ed95c692c9385c1332
parent5d023ad5bc648c9ed91d6860f6f706331542bfe5 (diff)
parentec0200c5cb574a32442c8aaeb0860a49fd962cb0 (diff)
downloadsubplot-f1c2110154cb153301f22906e793460e7236fbb8.tar.gz
Merge branch 'fix-205' into 'main'
pandoc: Add support for --citeproc Closes #205 See merge request subplot/subplot!215
-rw-r--r--src/doc.rs3
-rw-r--r--src/policy.rs24
2 files changed, 25 insertions, 2 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 2272581..c5bb2c7 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -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()));
+ }
+}