pub fn escape_html(s: &str) -> Cow<'_, str>Expand description
Escapes HTML special characters in a string.
This function replaces special characters with their HTML entity equivalents:
&becomes&<becomes<>becomes>"becomes"'becomes'
§Arguments
s- The string to escape
§Returns
Returns a Cow<str> containing either the original string if no escaping was
needed, or a new string with escaped characters.
§Examples
use html_generator::seo::escape_html;
let input = r#"<script>alert("Hello & goodbye")</script>"#;
let escaped = escape_html(input);
assert_eq!(
escaped,
r#"<script>alert("Hello & goodbye")</script>"#
);