Function escape

Source
pub fn escape<T, E>(
    text: T,
    escaper: E,
) -> Result<Safe<EscapeDisplay<T, E>>, Infallible>
Expand description

Escapes strings according to the escape mode.

Askama will automatically insert the first (Escaper) argument, so this filter only takes a single argument of any type that implements Display.

It is possible to optionally specify an escaper other than the default for the template’s extension, like {{ val|escape("txt") }}.

/// ```jinja
/// <div>{{ example|escape }}</div>
/// ```
#[derive(Template)]
#[template(ext = "html", in_doc = true)]
struct Example<'a> {
    example: &'a str,
}

assert_eq!(
    Example { example: "Escape <>&" }.to_string(),
    "<div>Escape &#60;&#62;&#38;</div>"
);