mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-29 05:51:32 +00:00

We adopted `askama_escape` with the other askama crates. It was not updated for quite some time, but still gets 25k+ downloads / day Mon to Fri. This PR re-adds the crate using our current HTML escaping function.
32 lines
1.3 KiB
Markdown
32 lines
1.3 KiB
Markdown
# askama_escape: HTML escaping, extracted from [Askama](https://askama.readthedocs.io/)
|
|
|
|
[](https://crates.io/crates/askama)
|
|
[](https://github.com/askama-rs/askama/actions/workflows/rust.yml)
|
|
[](https://docs.rs/askama_escape/)
|
|
|
|
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
|
|
|
|
```rust
|
|
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, "&");
|
|
```
|