HTML Escaping In Rust
```cargo
[dependencies]
html-escape = "0.2.13"
```
use html_escape::*;
fn main() {
let source = r#"_ < _ > _ " _ ' _ / _ & _"#;
println!("encode_safe: {}", encode_safe(source));
println!("encode_text: {}", encode_text(source));
println!("encode_quoted_attribute: {}", encode_quoted_attribute(source));
println!("encode_double_quoted_attribute: {}", encode_double_quoted_attribute(source));
println!("encode_single_quoted_attribute: {}", encode_single_quoted_attribute(source));
}
Output:
encode_safe: _ < _ > _ " _ ' _ / _ & _
encode_text: _ < _ > _ " _ ' _ / _ & _
encode_quoted_attribute: _ < _ > _ " _ ' _ / _ & _
encode_double_quoted_attribute: _ < _ > _ " _ ' _ / _ & _
encode_single_quoted_attribute: _ < _ > _ " _ ' _ / _ & _
Full Escape
```cargo
[dependencies]
html-escape = "0.2.13"
```
use html_escape::*;
fn main() {
let source = r#"_ < _ > _ " _ ' _ / _ & _"#;
println!("encode_unquoted_attribute: {}", encode_unquoted_attribute(source));
}
Output:
encode_unquoted_attribute: _ < _ > _ " _ ' _ / _ & _
Notes
- This is what I'm using in Neopoligen in additon to minijinja for the individual things like inline code tokens
-
There's also
escape_script
andescape_style
which deals with script and style tags. That's not what I'm interested in here.
-- end of line --