Expand description
HTML spec data and the answers the HTML spec gives — part of
tsv, published for tsv’s Svelte support
(tsv_svelte). The long-term target is a spec-faithful HTML
library; today the crate holds what tsv’s Svelte parser reads from the spec: the
named character references table, matched as the tokenizer matches it
(match_named_character_reference, answering a NamedCharacterReference).
The lookup is a pure function over text, independent of any one parser or tool. Names are
matched exactly, as authored: the lookup is case-sensitive, as the spec’s table is
(Á and á are different references).
use tsv_html::match_named_character_reference;
// `<` names `<`, its `;` included
let lt = match_named_character_reference("lt;").unwrap();
assert_eq!((lt.name(), lt.characters()), ("lt;", "<"));
// the longest name that starts the text wins: `∉` over `¬`
let notin = match_named_character_reference("notin;").unwrap();
assert_eq!((notin.name(), notin.characters()), ("notin;", "∉"));§Stability
The public signatures follow 0.x semver like every tsv crate: a breaking change ships only in a minor release. What the lookup answers may change in any release, tracking the spec and what tsv needs.
§License
The named-reference table is generated from WHATWG’s entities.json and compiled in
under BSD-3-Clause, beside tsv’s own 0BSD (the crate’s license is 0BSD AND BSD-3-Clause); the crate’s NOTICE file carries the attribution and both licenses.
Structs§
- Named
Character Reference - A named character reference
match_named_character_referencefound: a row of the spec’s named character references table, its name and the characters it stands for.
Functions§
- match_
named_ character_ reference - The longest named character reference at the start of
input, orNonewhen no name in the table starts it.