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//! Enable `runtime` for attributed model requests and token usage accounting,
4//! independently of prompt files or provider SDKs. Use [`render_checked`] to
5//! obtain immutable, validated text and section provenance before constructing
6//! a runtime fragment. See the [Rust guide](https://htmlp.dev/docs/runtime/).
7//!
8//! ```
9//! let doc = htmlp::parse(r#"<htmlp max-tokens="10k" reason="Shared context."><section id="task">Review.</section></htmlp>"#)?;
10//! assert_eq!(doc.get_element_by_id("task").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::{RenderedPrompt, RenderedSpan, SectionOrigin, TextMeasurement, render_checked};
20#[cfg(feature = "runtime")]
21pub mod runtime;
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};
27pub use signing::{budget_signature, sign_source};
28
29#[cfg(feature = "tokens")]
30mod tokenizer;
31#[cfg(feature = "tokens")]
32pub use tokenizer::Cl100k;