Skip to main content

htmlp/
lib.rs

1//! Strict, self-contained prompt files. The default library uses `xmlparser` and `sha2`; token counting is an injected [`TokenCounter`]. Enable `tokens`
2//! for CL100K, `json` for serialization, or `cli` for the standalone tool.
3//! Markup and the Rust API share one primitive: an [`Element`] with a name, an
4//! optional id, and budgets. Use [`Document::render`] to obtain immutable,
5//! validated text with per-element provenance. See the
6//! [Rust guide](https://htmlp.dev/docs/rust/).
7//!
8//! ```
9//! let doc = htmlp::parse(r#"<htmlp max-tokens="10k" reason="Shared context."><task id="review">Review.</task></htmlp>"#)?;
10//! assert_eq!(doc.get_element_by_id("review").unwrap().to_string(), "Review.");
11//! # Ok::<(), htmlp::Diagnostic>(())
12//! ```
13#![forbid(unsafe_code)]
14mod check;
15mod files;
16mod model;
17mod parser;
18mod rendered;
19pub use rendered::{
20    ElementOrigin, RenderedDocument, RenderedElement, RenderedSpan, TextMeasurement, render_checked,
21};
22mod signing;
23pub use check::{TokenCounter, lint, render};
24pub use files::{FileReport, check_path, parse_file, sign_path};
25pub use model::*;
26pub use parser::{parse, parse_limit, parse_template};
27pub use signing::{budget_signature, sign_source};
28
29#[cfg(feature = "tokens")]
30mod tokenizer;
31#[cfg(feature = "tokens")]
32pub use tokenizer::Cl100k;