Function pulldown_cmark_escape::escape_html
source · pub fn escape_html<W: StrWrite>(w: W, s: &str) -> Result<(), W::Error>
Expand description
Writes the given string to the Write sink, replacing special HTML bytes (<, >, &, “, ’) by escape sequences.
Use this function to write output to quoted HTML attributes. Since this function doesn’t escape spaces, unquoted attributes cannot be used. For example:
let mut value = String::new();
pulldown_cmark_escape::escape_html(&mut value, "two words")
.expect("writing to a string is infallible");
// This is okay.
let ok = format!("<a title='{value}'>test</a>");
// This is not okay.
//let not_ok = format!("<a title={value}>test</a>");