Crates.io | askama_escape |
lib.rs | askama_escape |
version | 0.13.0 |
created_at | 2018-11-07 20:38:00.547881+00 |
updated_at | 2025-03-27 16:51:18.318471+00 |
description | HTML escaping, extracted from Askama |
homepage | https://askama.readthedocs.io/ |
repository | https://github.com/askama-rs/askama |
max_upload_size | |
id | 95338 |
size | 49,216 |
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 '>'
.
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, "&");