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 chrome;
34mod compress;
35mod d2;
36mod directives;
37mod error;
38mod fences;
39mod lean;
40mod seo;
41mod serve;
42
43pub use chrome::{
44 extract_toc, page as chrome_page, Chrome, NavGroup, TocEntry, LAYOUT_CSS as chrome_layout_css,
45};
46pub use compress::{ext_token, pick_encoding, sidecar_path, Tools};
47pub use directives::{resolve, BuildContext};
48pub use error::CompilerError;
49pub use fences::{scan, Directive, DirectiveKind, Scanned};
50pub use seo::{
51 document, first_h1, first_paragraph, llms_txt, robots_txt, sitemap_xml, split_front_matter,
52 PageMeta, SeoPage, SiteConfig,
53};
54pub use serve::{compile_site, compile_site_with, mime_for, resolve_route, SiteReport};
55
56/// Compile one markdown document into a static HTML page.
57///
58/// Directive fences (`include-symbol`, `witness`, `lean-check`) resolve
59/// through the owning crate and become raw HTML; island fences and all
60/// other markdown render through docs-core (M1 contract unchanged).
61pub fn compile(source: &str, ctx: &BuildContext) -> Result<String, CompilerError> {
62 let scanned = scan(source);
63 let resolved = scanned.substitute(|d| resolve(d, ctx))?;
64 docs_core::render(&resolved, &ctx.asset_base).map_err(CompilerError::Render)
65}
66
67/// The crate's version, for callers that report it.
68pub const VERSION: &str = env!("CARGO_PKG_VERSION");