refactor: remove askama_html dependency
This commit is contained in:
parent
6e77a2198d
commit
082d1c6c92
4 changed files with 27 additions and 17 deletions
|
|
@ -312,6 +312,24 @@ where
|
|||
.ok()
|
||||
}
|
||||
|
||||
/// Replace all html control characters to make a string safe for inserting into HTML.
|
||||
pub fn escape_html(input: &str) -> String {
|
||||
let mut buf = String::with_capacity(input.len());
|
||||
|
||||
for c in input.chars() {
|
||||
match c {
|
||||
'<' => buf.push_str("<"),
|
||||
'>' => buf.push_str(">"),
|
||||
'&' => buf.push_str("&"),
|
||||
'"' => buf.push_str("""),
|
||||
'\'' => buf.push_str("'"),
|
||||
'\n' => buf.push_str("<br>"),
|
||||
_ => buf.push(c),
|
||||
};
|
||||
}
|
||||
buf
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::BufReader, path::Path};
|
||||
|
|
|
|||
Reference in a new issue