rdom-parser
HTML-ish template parser for rdom-core. The
parseFromString equivalent for the rdom family.
Hand-rolled recursive descent. Zero runtime dependencies beyond rdom-core.
Quick start
use parse;
use Dom;
let : = parse.unwrap;
For building into an existing tree:
use parse_into;
let mut dom: = new;
let body = dom.create_element;
dom.append_child.unwrap;
let children = parse_into?;
Supported
- Start, end, self-closing tags; case-insensitive tag names (normalized to lowercase)
- Void elements (
<br>,<hr>,<img>,<input>, …) auto-close - Attributes:
name="value",name='value',name=value,name(boolean) class="a b c"populates the classList- Text with entity decoding:
&,<,>,",', ,&#NNN;,&#xHH; - Comments:
<!-- … -->preserved as Comment nodes - Full UTF-8: CJK, emoji, ZWJ sequences, combining marks all preserved correctly
Not supported
<!DOCTYPE>— skip in your source if you have it- CDATA sections, namespace prefixes, processing instructions
<script>/<style>raw-text mode (our DOM has no corresponding tags)- Mismatched tags — errors, not auto-repaired
Error reporting
ParseError carries line + column + byte offset + optional hint:
use parse;
use Dom;
let err = .unwrap_err;
assert!;
assert!;
println!; // "parse error at line 1, col 14: …"
Round-tripping
For a well-behaved subset, parse(x).outer_markup() == x:
let src = "<div><p>Hello & world</p></div>";
let = .unwrap;
assert_eq!;
Caveats: attributes serialize in alphabetic order, classes serialize
in alphabetic order, text entities only escape & < > (not " or '
outside attributes).
Examples
parse_html walks a parsed tree and runs selector queries;
round_trip verifies parse ↔ serialize equivalence on a corpus
of well-behaved snippets.
For an end-to-end "parse → cascade → paint to terminal" demo, see
rdom-tui's parse_and_render example.
Testing
92 tests covering parsing, entity decoding, nesting, errors, round-tripping, realistic template snippets, and Unicode content.