Expand description
HTML and XML escaping.
There are three distinct HTML/XML escapers and the golden fixtures depend on the differences
between them. (The original spec, docs/history/MOLT_SPEC.md §3.3, shows only one;
following it would change the output.)
| function | escapes | notes |
|---|---|---|
escape_text | & < > " ' | & first; ' becomes ' |
escape_attribute | & " ' | not < or > |
escape_xml | & < > " ' | ' becomes ', the XML spelling; XML-illegal characters dropped |
escape_json_script | < > & U+2028 U+2029 | JSON \uXXXX escapes, for JSON inside <script>; not HTML escaping |
Escaping is applied once, when content enters the tree — never at render time.
That is why crate::core::Node::Raw exists as the documented escape hatch.
Functions§
- escape_
attribute - Escapes a value for use inside a double-quoted HTML attribute.
- escape_
json_ script - Makes a JSON document safe to place inside a
<script>element. - escape_
text - Escapes text for use as HTML element content.
- escape_
text_ with_ slashes - Escapes text for HTML content, optionally escaping
/as well. - escape_
xml - Escapes text for XML content — used by the sitemap and RSS generators.