Skip to main content

escape_attribute

Function escape_attribute 

Source
pub fn escape_attribute(value: &str) -> String
Expand description

Escapes a value for use inside a double-quoted HTML attribute.

&, <, > and " are replaced; an apostrophe is left alone because it cannot terminate a double-quoted attribute, which keeps rendered meta tags readable.

ยงExample

use metadata_gen::escape_attribute;

assert_eq!(
    escape_attribute(r#"Fish & "Chips" <it's>"#),
    "Fish &amp; &quot;Chips&quot; &lt;it's&gt;"
);