Skip to main content

Module escape

Module escape 

Source
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.)

functionescapesnotes
escape_text& < > " '& first; ' becomes &#x27;
escape_attribute& " 'not < or >
escape_xml& < > " '' becomes &apos;, the XML spelling; XML-illegal characters dropped
escape_json_script< > & U+2028 U+2029JSON \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.