Expand description
§askama_escape: HTML escaping, extracted from Askama
Useful if you don’t need a template engine, but if you need to escape a text for HTML or XML.
This implementation escapes '"'
, '&'
, '\'',
'<'
and '>'
.
§Example
use askama_escape::{escape, escape_html, escape_html_char, Html};
assert_eq!(
escape("<script>alert('Hello & bye!')</script>", Html).to_string(),
"<script>alert('Hello & bye!')</script>",
);
let mut dest = String::new();
escape_html(&mut dest, "<script>alert('Hello & bye!')</script>").unwrap();
assert_eq!(
dest,
"<script>alert('Hello & bye!')</script>",
);
let mut dest = String::new();
escape_html_char(&mut dest, '&').unwrap();
assert_eq!(dest, "&");
Structs§
- Escaped
- The return type of
escape()
. - Html
- Escape for HTML or XML.
- Text
- Escape for plain text, i.e. pass through unchanged.
Traits§
Functions§
- escape
- Safely wrap a
string
with someescaper
e.g. for the use inHtml
. - escape_
html - HTML/XML escape a string
str
intodest
. - escape_
html_ char - HTML/XML escape a character
c
intodest
.