docs_compiler/lib.rs
1//! docs-compiler: the composition CLI for the estate's docs crates
2//! (docs-core extension program, SPEC.md M3/M4).
3//!
4//! The pipeline is small and honest: scan a markdown document for the
5//! four directive kinds, resolve each one through the crate that owns it
6//! (`include-symbol` through docs-symbols, `witness` through
7//! docs-witness, `lean-check` through an out-of-process `lean` plus
8//! docs-proof, islands natively through docs-core), substitute the
9//! resulting raw HTML, and render the page with docs-core. Any failing
10//! directive fails the build with a typed error naming its source;
11//! nothing degrades to a silent placeholder.
12//!
13//! ```
14//! use docs_compiler::BuildContext;
15//!
16//! // No directives: the document flows through docs-core untouched.
17//! let html = docs_compiler::compile(
18//! "# Title\n\nSome *prose*.\n",
19//! &BuildContext::new("."),
20//! )
21//! .unwrap();
22//! assert!(html.contains("<h1>Title</h1>"));
23//! ```
24//!
25//! # Layer
26//!
27//! L3 - composition. Depends on docs-core (L2) and the capability
28//! crates (L0/L1); spawns `lean` as an external process (REQ-P1).
29
30#![deny(missing_docs)]
31#![forbid(unsafe_code)]
32
33mod compress;
34mod d2;
35mod directives;
36mod error;
37mod fences;
38mod lean;
39mod seo;
40mod serve;
41
42pub use compress::{ext_token, pick_encoding, sidecar_path, Tools};
43pub use directives::{resolve, BuildContext};
44pub use error::CompilerError;
45pub use fences::{scan, Directive, DirectiveKind, Scanned};
46pub use seo::{
47 document, first_h1, first_paragraph, llms_txt, robots_txt, sitemap_xml, split_front_matter,
48 PageMeta, SeoPage, SiteConfig,
49};
50pub use serve::{compile_site, mime_for, resolve_route, SiteReport};
51
52/// Compile one markdown document into a static HTML page.
53///
54/// Directive fences (`include-symbol`, `witness`, `lean-check`) resolve
55/// through the owning crate and become raw HTML; island fences and all
56/// other markdown render through docs-core (M1 contract unchanged).
57pub fn compile(source: &str, ctx: &BuildContext) -> Result<String, CompilerError> {
58 let scanned = scan(source);
59 let resolved = scanned.substitute(|d| resolve(d, ctx))?;
60 docs_core::render(&resolved, "/_assets").map_err(CompilerError::Render)
61}
62
63/// The crate's version, for callers that report it.
64pub const VERSION: &str = env!("CARGO_PKG_VERSION");