Skip to main content

latexml_core/common/relaxng/
embedded.rs

1//! Embedded RelaxNG schema tree — bundled at compile time so a
2//! single-binary distribution can serve compiled `.model` files and
3//! `.rng` schemas without an accompanying `resources/RelaxNG/` tree
4//! on disk.
5//!
6//! The manifest is generated by `latexml_core/build.rs`, which walks
7//! `resources/RelaxNG/` and emits a static `&[(relative_path,
8//! file_content)]` array. Consumers call [`lookup`] with a
9//! tree-relative path and feed the returned `&'static str` straight
10//! into whatever parser needs it:
11//!
12//! * `.model` files (compiled tag/attr/content schema) → fed to `Model::load_compiled_schema_str`
13//!   as text.
14//! * `.rng` files → fed to `libxml::parser::Parser::parse_string` in `super::scan::scan_external`,
15//!   where `<rng:include>` recursion is handled at the Rust scanner level (each include re-enters
16//!   `scan_external` and re-hits the lookup table).
17//!
18//! Nothing is materialised to disk — the prebuilt binary runs every
19//! schema-driven feature (`--validate`, `--schemadocs`, the
20//! always-on `.model` lookup at startup) directly from
21//! `.rodata`.
22
23include!(concat!(env!("OUT_DIR"), "/embedded_relaxng.rs"));
24
25/// Look up the embedded RelaxNG bytes by their tree-relative path
26/// (e.g. `"LaTeXML.model"`, `"LaTeXML-common.rng"`, or
27/// `"svg/svg11.rng"`). Returns `None` if the name isn't in the
28/// generated manifest.
29pub fn lookup(rel_path: &str) -> Option<&'static str> {
30  FILES
31    .iter()
32    .find_map(|(p, c)| (*p == rel_path).then_some(*c))
33}