HTML Escape
This library is for encoding/escaping special characters in HTML and decoding/unescaping HTML entities as well.
Usage
Encoding
This crate provides some encode_* functions to encode HTML text in different situations.
Escaping is context-sensitive.
Use encode_text for text, quoted attribute encoders for quoted attributes, encode_unquoted_attribute for unquoted attributes, and script or style encoders for raw-text elements.
encode_safe is not a context-independent sanitizer.
For example, to put a text between a start tag <foo> and an end tag </foo>, use the encode_text function to escape every &, <, and > in the text.
assert_eq!;
The functions suffixed with _to_writer, _to_vec or _to_string are useful to generate HTML.
let mut html = Stringfrom;
assert_eq!;
html.push_str;
assert_eq!;
html.push_str;
assert_eq!;
html.push_str;
assert_eq!;
Decoding
Decoding accepts exact named and numeric character references ending with ;.
It does not apply legacy semicolonless references or C1 control replacements used by browser tokenizers.
assert_eq!;
assert_eq!;
No Std
Disable the default features to compile this crate without std.
[]
= "*"
= false
Benchmark
Crates.io
https://crates.io/crates/html-escape