summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-08-13 16:14:33 +0300
committerLars Wirzenius <liw@liw.fi>2022-08-14 09:07:23 +0300
commit82cf29e251685de8ea6c14fff5d1b1b3d7001fe5 (patch)
treef934f27ca6ebcc14d0d018d9ee8e9d9cfdc6b732 /src
parente90337da2b293eb0111e6be9131ef2f25e861b9c (diff)
downloadsubplot-82cf29e251685de8ea6c14fff5d1b1b3d7001fe5.tar.gz
feat! drop support to act as a Pandoc filter
When we change Subplot to take a YAML file instead of a Markdown file as input, it doesn't make sense to act as a Pandoc filter anymore: Pandoc doesn't understand our YAML file. In any case, I seem to have been the only user ever of that feature, so it won't really bother anyone else. Even so, we should treat this as a breaking change. "subplot docgen" still works as before. Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/bin/subplot-filter.rs16
-rw-r--r--src/bin/subplot.rs60
2 files changed, 2 insertions, 74 deletions
diff --git a/src/bin/subplot-filter.rs b/src/bin/subplot-filter.rs
deleted file mode 100644
index 6c01241..0000000
--- a/src/bin/subplot-filter.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use anyhow::Result;
-use std::io::{self, Read, Write};
-use subplot::{Document, Style};
-
-fn main() -> Result<()> {
- let mut buffer = String::new();
- let mut stdin = io::stdin();
- stdin.read_to_string(&mut buffer)?;
- let basedir = std::path::Path::new(".");
- let style = Style::default();
- let mut doc = Document::from_json(&basedir, vec![], &buffer, style, None)?;
- doc.typeset();
- let bytes = doc.ast()?.into_bytes();
- io::stdout().write_all(&bytes)?;
- Ok(())
-}
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 5e802b4..759b70b 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -13,8 +13,8 @@ use time::{format_description::FormatItem, macros::format_description, OffsetDat
use clap::{CommandFactory, FromArgMatches, Parser};
use std::convert::TryFrom;
use std::ffi::OsString;
-use std::fs::{self, write, File};
-use std::io::{Read, Write};
+use std::fs::{self, write};
+use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::time::UNIX_EPOCH;
@@ -53,7 +53,6 @@ impl Toplevel {
#[derive(Debug, Parser)]
enum Cmd {
Extract(Extract),
- Filter(Filter),
Metadata(Metadata),
Docgen(Docgen),
Codegen(Codegen),
@@ -65,7 +64,6 @@ impl Cmd {
fn run(&self) -> Result<()> {
match self {
Cmd::Extract(e) => e.run(),
- Cmd::Filter(f) => f.run(),
Cmd::Metadata(m) => m.run(),
Cmd::Docgen(d) => d.run(),
Cmd::Codegen(c) => c.run(),
@@ -76,7 +74,6 @@ impl Cmd {
fn doc_path(&self) -> Option<&Path> {
match self {
Cmd::Extract(e) => e.doc_path(),
- Cmd::Filter(f) => f.doc_path(),
Cmd::Metadata(m) => m.doc_path(),
Cmd::Docgen(d) => d.doc_path(),
Cmd::Codegen(c) => c.doc_path(),
@@ -194,59 +191,6 @@ impl Extract {
}
#[derive(Debug, Parser)]
-/// Filter a pandoc JSON document.
-///
-/// This filters a pandoc JSON document, applying Subplot's formatting rules and
-/// image conversion support.
-///
-/// If input/output filename is provided, this operates on STDIN/STDOUT.
-struct Filter {
- #[clap(name = "INPUT", long = "input", short = 'i', parse(from_os_str))]
- /// Input file (uses STDIN if omitted)
- input: Option<PathBuf>,
-
- #[clap(name = "OUTPUT", long = "output", short = 'o', parse(from_os_str))]
- /// Output file (uses STDOUT if omitted)
- output: Option<PathBuf>,
-
- #[clap(name = "BASE", long = "base", short = 'b', parse(from_os_str))]
- /// Base directory (defaults to dir of input if given, or '.' if using STDIN)
- base: Option<PathBuf>,
-}
-
-impl Filter {
- fn doc_path(&self) -> Option<&Path> {
- self.input.as_deref().and_then(Path::parent)
- }
-
- fn run(&self) -> Result<()> {
- let mut buffer = String::new();
- if let Some(filename) = &self.input {
- File::open(filename)?.read_to_string(&mut buffer)?;
- } else {
- std::io::stdin().read_to_string(&mut buffer)?;
- }
- let basedir = if let Some(path) = &self.base {
- path.as_path()
- } else if let Some(path) = &self.input {
- path.parent().unwrap_or_else(|| Path::new("."))
- } else {
- Path::new(".")
- };
- let style = Style::default();
- let mut doc = Document::from_json(basedir, vec![], &buffer, style, None)?;
- doc.typeset();
- let bytes = doc.ast()?.into_bytes();
- if let Some(filename) = &self.output {
- File::create(filename)?.write_all(&bytes)?;
- } else {
- std::io::stdout().write_all(&bytes)?;
- }
- Ok(())
- }
-}
-
-#[derive(Debug, Parser)]
/// Extract metadata about a document
///
/// Load and process a subplot document, extracting various metadata about the