rdom_parser/lib.rs
1//! # rdom-parser — HTML-ish template parser for rdom-core
2//!
3//! Turns a template string into a `Dom<Ext>` tree. The `parseFromString`
4//! equivalent for the rdom family of crates.
5//!
6//! ## Quick start
7//!
8//! ```
9//! use rdom_parser::parse;
10//! use rdom_core::Dom;
11//!
12//! let (dom, ids): (Dom<()>, _) = parse(r#"
13//! <div class="hero" id="main">
14//! <h1>Welcome</h1>
15//! <p>Hello & <strong>world</strong></p>
16//! </div>
17//! "#).unwrap();
18//!
19//! let div = ids.iter().find(|&&id| dom.node(id).tag_name() == Some("div")).unwrap();
20//! assert!(dom.node(*div).has_class("hero"));
21//! ```
22//!
23//! ## Supported
24//!
25//! - Start / end / self-closing tags, case-insensitive tag names
26//! - Void elements (`<br>`, `<hr>`, `<img>`, …) auto-close
27//! - Attributes: `name="value"`, `name='value'`, `name=value`, `name`
28//! (boolean). `class="a b c"` populates the classList.
29//! - Text with entity decoding: `& < > " '
30//! &#NNN; &#xHH;`
31//! - Comments: `<!-- … -->` preserved as Comment nodes
32//! - Case-insensitive tag names (normalized to lowercase)
33//! - Attribute names preserved case
34//!
35//! ## Not supported (out of scope)
36//!
37//! - `<!DOCTYPE>` — no need for a TUI DOM
38//! - CDATA sections, namespace prefixes, processing instructions
39//! - `<script>` / `<style>` raw-text mode (our DOM doesn't have these)
40//! - Mismatched tags are errors, not auto-repaired
41//!
42//! ## Error reporting
43//!
44//! `ParseError` carries line/col/pos + optional hint:
45//!
46//! ```
47//! # use rdom_parser::parse;
48//! # use rdom_core::Dom;
49//! let err = parse::<()>("<div><span></p></div>").unwrap_err();
50//! assert!(err.msg.contains("mismatched"));
51//! assert!(err.hint.is_some());
52//! ```
53
54mod dom_ext;
55mod error;
56mod parser;
57
58pub use dom_ext::NodeMutHtml;
59pub use error::{ParseError, Result};
60pub use parser::{parse, parse_into};