Skip to main content

publish/
publish.rs

1//! Smoke helper: `cargo run -p docutils-core --example publish -- file.rst`.
2//!
3//! Parity shape: HTML comes from the string pipeline (writer transforms),
4//! while astext/messages come from the doctree pipeline (null writer),
5//! mirroring how the harness reads the oracle.
6
7use docutils_core::core::{publish_doctree_with, publish_string_with};
8use docutils_core::settings::Settings;
9
10fn main() {
11    let path = std::env::args().nth(1).expect("usage: publish <file.rst>");
12    let source = std::fs::read_to_string(&path).expect("read input");
13    // Parity harness: report everything (mirrors the oracle at
14    // report_level 1); default filtering is covered by unit tests.
15    let settings = Settings {
16        report_level: 1,
17        ..Settings::default()
18    };
19    let doc = match publish_doctree_with(&source, &settings, None) {
20        Ok(doc) => doc,
21        Err(h) => {
22            eprintln!("HALT {h}");
23            std::process::exit(1);
24        }
25    };
26    eprintln!("-- messages:");
27    for m in &doc.messages {
28        let line = m
29            .line
30            .map(|n| n.to_string())
31            .unwrap_or_else(|| "None".into());
32        eprintln!(
33            "MSG level={} line={} {}",
34            m.level,
35            line,
36            m.text.replace('\n', "\\n")
37        );
38    }
39    eprintln!("-- astext --");
40    eprintln!("{}", doc.astext());
41    match publish_string_with(&source, &settings, None) {
42        Ok((html, _)) => println!("{html}"),
43        Err(h) => {
44            eprintln!("HALT {h}");
45            std::process::exit(1);
46        }
47    }
48}