Crate askama_escape

Source
Expand description

§askama_escape: HTML escaping, extracted from Askama

Crates.io GitHub Workflow Status docs.rs

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(),
    "&#60;script&#62;alert(&#39;Hello &#38; bye!&#39;)&#60;/script&#62;",
);

let mut dest = String::new();
escape_html(&mut dest, "<script>alert('Hello & bye!')</script>").unwrap();
assert_eq!(
    dest,
    "&#60;script&#62;alert(&#39;Hello &#38; bye!&#39;)&#60;/script&#62;",
);

let mut dest = String::new();
escape_html_char(&mut dest, '&').unwrap();
assert_eq!(dest, "&#38;");

Structs§

Escaped
The return type of escape().
Html
Escape for HTML or XML.
Text
Escape for plain text, i.e. pass through unchanged.

Traits§

Escaper
An escaper for some context, e.g. Html.

Functions§

escape
Safely wrap a string with some escaper e.g. for the use in Html.
escape_html
HTML/XML escape a string str into dest.
escape_html_char
HTML/XML escape a character c into dest.