diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-04-05 19:04:03 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-04-08 16:56:30 +0300 |
commit | 602f5c524fe60d8a9400aec1a39dda8cb208823e (patch) | |
tree | 9e3b7792c3224a50b4325dca881dd930925d8d33 /src/bin/subplot.rs | |
parent | 96e20dcd5256e18bd5a0bad237af078bfdfcf694 (diff) | |
download | subplot-602f5c524fe60d8a9400aec1a39dda8cb208823e.tar.gz |
feat: change main program to not use Pandoc
Sponsored-by: author
Diffstat (limited to 'src/bin/subplot.rs')
-rw-r--r-- | src/bin/subplot.rs | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs index 7998416..41d8894 100644 --- a/src/bin/subplot.rs +++ b/src/bin/subplot.rs @@ -221,7 +221,7 @@ impl Metadata { #[derive(Debug, Parser)] /// Typeset subplot document /// -/// Process a subplot document and typeset it using Pandoc. +/// Process a subplot document and typeset it. struct Docgen { /// Allow warnings in document? #[clap(long)] @@ -254,7 +254,6 @@ impl Docgen { let style = Style::default(); let mut doc = load_linted_doc(&self.input, style, self.template.as_deref(), self.merciful)?; - let mut pandoc = pandoc::new(); // Metadata date from command line or file mtime. However, we // can't set it directly, since we don't want to override the date // in the actual document, if given, so we only set @@ -268,28 +267,11 @@ impl Docgen { let filename = doc.meta().basedir().join(doc.meta().markdown_filename()); Self::mtime_formatted(Self::mtime(&filename)?) }; - pandoc.add_option(pandoc::PandocOption::Meta("date".to_string(), Some(date))); - pandoc.add_option(pandoc::PandocOption::TableOfContents); - pandoc.add_option(pandoc::PandocOption::Standalone); - pandoc.add_option(pandoc::PandocOption::NumberSections); if Self::need_output(&mut doc, self.template.as_deref(), &self.output) { doc.typeset(&mut Warnings::default()); - pandoc.set_input_format(pandoc::InputFormat::Json, vec![]); - pandoc.set_input(pandoc::InputKind::Pipe(doc.ast()?)); - pandoc.set_output(pandoc::OutputKind::File(self.output.clone())); - - debug!("Executing pandoc to produce {}", self.output.display()); - let r = pandoc.execute(); - if let Err(pandoc::PandocError::Err(output)) = r { - let code = output.status.code().unwrap_or(127); - let stderr = String::from_utf8_lossy(&output.stderr); - error!("Failed to execute Pandoc: exit code {}", code); - error!("{}", stderr.strip_suffix('\n').unwrap()); - - return Err(anyhow::Error::msg("Pandoc failed")); - } - r?; + std::fs::write(&self.output, doc.to_html(&date)) + .map_err(|e| SubplotError::WriteFile(self.output.clone(), e))?; } Ok(()) |