Expand description
§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.
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!("a > b && a < c", html_escape::encode_text("a > b && a < c"));The functions suffixed with _to_writer, _to_vec or _to_string are useful to generate HTML.
let mut html = String::from("<input value=");
assert_eq!("Hello world!", html_escape::encode_unquoted_attribute_to_string("Hello world!", &mut html));
html.push_str(" placeholder=\"");
assert_eq!("The default value is "Hello world!".", html_escape::encode_double_quoted_attribute_to_string("The default value is \"Hello world!\".", &mut html));
html.push_str("\"/><script>alert('");
assert_eq!(r"<script>\'s end tag is <\/script>", html_escape::encode_script_single_quoted_text_to_string("<script>'s end tag is </script>", &mut html));
html.push_str("');</script>");
assert_eq!("<input value=Hello world! placeholder=\"The default value is "Hello world!".\"/><script>alert(\'<script>\\\'s end tag is <\\/script>\');</script>", html);§Decoding
assert_eq!("Hello world!", html_escape::decode_html_entities("Hello world!"));assert_eq!("alert('<script></script>');", html_escape::decode_script(r"alert('<script><\/script>');"));§No Std
Disable the default features to compile this crate without std.
[dependencies.html-escape]
version = "*"
default-features = false§Benchmark
cargo benchStatics§
- NAMED_
ENTITIES - The table of HTML named entities ordered by the names.
Functions§
- decode_
html_ entities - Decode html entities in a given string.
- decode_
html_ entities_ to_ string - Decode html entities in a given string to a mutable
Stringreference and return the decoded string slice. - decode_
html_ entities_ to_ vec - Decode html entities in a given string to a mutable
Vec<u8>reference and return the decoded data slice. - decode_
html_ entities_ to_ writer - Decode html entities in a given string to a writer.
- decode_
script - Decode text from the
<script>element. - decode_
script_ double_ quoted_ text - Decode text from a double quoted text in the
<script>element. - decode_
script_ double_ quoted_ text_ to_ string - Write text from a double quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - decode_
script_ double_ quoted_ text_ to_ vec - Write text from a double quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
script_ double_ quoted_ text_ to_ writer - Write text from a double quoted text in the
<script>element to a writer. - decode_
script_ quoted_ text - Decode text from a quoted text in the
<script>element. - decode_
script_ quoted_ text_ to_ string - Write text from a quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - decode_
script_ quoted_ text_ to_ vec - Write text from a quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
script_ quoted_ text_ to_ writer - Write text from a quoted text in the
<script>element to a writer. - decode_
script_ single_ quoted_ text - Decode text from a single quoted text in the
<script>element. - decode_
script_ single_ quoted_ text_ to_ string - Write text from a single quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - decode_
script_ single_ quoted_ text_ to_ vec - Write text from a single quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
script_ single_ quoted_ text_ to_ writer - Write text from a single quoted text in the
<script>element to a writer. - decode_
script_ to_ string - Write text from the
<script>element to a mutableStringreference and return the encoded string slice. - decode_
script_ to_ vec - Write text from the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
script_ to_ writer - Write text from the
<script>element to a writer. - decode_
style - Decode text from the
<style>element. - decode_
style_ double_ quoted_ text - Decode text from a double quoted text in the
<style>element. - decode_
style_ double_ quoted_ text_ to_ string - Write text from a double quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - decode_
style_ double_ quoted_ text_ to_ vec - Write text from a double quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
style_ double_ quoted_ text_ to_ writer - Write text from a double quoted text in the
<style>element to a writer. - decode_
style_ quoted_ text - Decode text from a quoted text in the
<style>element. - decode_
style_ quoted_ text_ to_ string - Write text from a quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - decode_
style_ quoted_ text_ to_ vec - Write text from a quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
style_ quoted_ text_ to_ writer - Write text from a quoted text in the
<style>element to a writer. - decode_
style_ single_ quoted_ text - Decode text from a single quoted text in the
<style>element. - decode_
style_ single_ quoted_ text_ to_ string - Write text from a single quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - decode_
style_ single_ quoted_ text_ to_ vec - Write text from a single quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
style_ single_ quoted_ text_ to_ writer - Write text from a single quoted text in the
<style>element to a writer. - decode_
style_ to_ string - Write text from the
<style>element to a mutableStringreference and return the encoded string slice. - decode_
style_ to_ vec - Write text from the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - decode_
style_ to_ writer - Write text from the
<style>element to a writer. - encode_
double_ quoted_ attribute - Encode text used in a double-quoted attribute.
- encode_
double_ quoted_ attribute_ to_ string - Write text used in a double-quoted attribute to a mutable
Stringreference and return the encoded string slice. - encode_
double_ quoted_ attribute_ to_ vec - Write text used in a double-quoted attribute to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
double_ quoted_ attribute_ to_ writer - Write text used in a double-quoted attribute to a writer.
- encode_
quoted_ attribute - Encode text used in a quoted attribute.
- encode_
quoted_ attribute_ to_ string - Write text used in a quoted attribute to a mutable
Stringreference and return the encoded string slice. - encode_
quoted_ attribute_ to_ vec - Write text used in a quoted attribute to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
quoted_ attribute_ to_ writer - Write text used in a quoted attribute to a writer.
- encode_
safe - Encode text to prevent special characters functioning.
- encode_
safe_ to_ string - Encode text to prevent special characters functioning and write it to a mutable
Stringreference and return the encoded string slice. - encode_
safe_ to_ vec - Encode text to prevent special characters functioning and write it to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
safe_ to_ writer - Encode text to prevent special characters functioning and write it to a writer.
- encode_
script - Encode text used in the
<script>element. - encode_
script_ double_ quoted_ text - Encode text used in a double quoted text in the
<script>element. - encode_
script_ double_ quoted_ text_ to_ string - Write text used in a double quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - encode_
script_ double_ quoted_ text_ to_ vec - Write text used in a double quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
script_ double_ quoted_ text_ to_ writer - Write text used in a double quoted text in the
<script>element to a writer. - encode_
script_ quoted_ text - Encode text used in a quoted text in the
<script>element. - encode_
script_ quoted_ text_ to_ string - Write text used in a quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - encode_
script_ quoted_ text_ to_ vec - Write text used in a quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
script_ quoted_ text_ to_ writer - Write text used in a quoted text in the
<script>element to a writer. - encode_
script_ single_ quoted_ text - Encode text used in a single quoted text in the
<script>element. - encode_
script_ single_ quoted_ text_ to_ string - Write text used in a single quoted text in the
<script>element to a mutableStringreference and return the encoded string slice. - encode_
script_ single_ quoted_ text_ to_ vec - Write text used in a single quoted text in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
script_ single_ quoted_ text_ to_ writer - Write text used in a single quoted text in the
<script>element to a writer. - encode_
script_ to_ string - Write text used in the
<script>element to a mutableStringreference and return the encoded string slice. - encode_
script_ to_ vec - Write text used in the
<script>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
script_ to_ writer - Write text used in the
<script>element to a writer. - encode_
single_ quoted_ attribute - Encode text used in a single-quoted attribute.
- encode_
single_ quoted_ attribute_ to_ string - Write text used in a single-quoted attribute to a mutable
Stringreference and return the encoded string slice. - encode_
single_ quoted_ attribute_ to_ vec - Write text used in a single-quoted attribute to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
single_ quoted_ attribute_ to_ writer - Write text used in a single-quoted attribute to a writer.
- encode_
style - Encode text used in the
<style>element. - encode_
style_ double_ quoted_ text - Encode text used in a double quoted text in the
<style>element. - encode_
style_ double_ quoted_ text_ to_ string - Write text used in a double quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - encode_
style_ double_ quoted_ text_ to_ vec - Write text used in a double quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
style_ double_ quoted_ text_ to_ writer - Write text used in a double quoted text in the
<style>element to a writer. - encode_
style_ quoted_ text - Encode text used in a quoted text in the
<style>element. - encode_
style_ quoted_ text_ to_ string - Write text used in a quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - encode_
style_ quoted_ text_ to_ vec - Write text used in a quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
style_ quoted_ text_ to_ writer - Write text used in a quoted text in the
<style>element to a writer. - encode_
style_ single_ quoted_ text - Encode text used in a single quoted text in the
<style>element. - encode_
style_ single_ quoted_ text_ to_ string - Write text used in a single quoted text in the
<style>element to a mutableStringreference and return the encoded string slice. - encode_
style_ single_ quoted_ text_ to_ vec - Write text used in a single quoted text in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
style_ single_ quoted_ text_ to_ writer - Write text used in a single quoted text in the
<style>element to a writer. - encode_
style_ to_ string - Write text used in the
<style>element to a mutableStringreference and return the encoded string slice. - encode_
style_ to_ vec - Write text used in the
<style>element to a mutableVec<u8>reference and return the encoded data slice. - encode_
style_ to_ writer - Write text used in the
<style>element to a writer. - encode_
text - Encode text used as regular HTML text.
- encode_
text_ minimal - Encode text used as regular HTML text.
- encode_
text_ minimal_ to_ string - Write text used as regular HTML text to a mutable
Stringreference and return the encoded string slice. - encode_
text_ minimal_ to_ vec - Write text used as regular HTML text to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
text_ minimal_ to_ writer - Write text used as regular HTML text to a writer.
- encode_
text_ to_ string - Write text used as regular HTML text to a mutable
Stringreference and return the encoded string slice. - encode_
text_ to_ vec - Write text used as regular HTML text to a mutable
Vec<u8>reference and return the encoded data slice. - encode_
text_ to_ writer - Write text used as regular HTML text to a writer.
- encode_
unquoted_ attribute - Encode text used in an unquoted attribute. Except for alphanumeric characters, escape all characters which are less than 128.
- encode_
unquoted_ attribute_ to_ string - Write text used in an unquoted attribute to a mutable
Stringreference and return the encoded string slice. Except for alphanumeric characters, escape all characters which are less than 128. - encode_
unquoted_ attribute_ to_ vec - Write text used in an unquoted attribute to a mutable
Vec<u8>reference and return the encoded data slice. Except for alphanumeric characters, escape all characters which are less than 128. - encode_
unquoted_ attribute_ to_ writer - Write text used in an unquoted attribute to a writer. Except for alphanumeric characters, escape all characters which are less than 128.