Function build_html::escape_html

source ·
pub fn escape_html(data: &str) -> String
Expand description

Escape the provided string.

All HTML tags will be converted to their escaped versions. The output string should be safe to insert into an HTML document. Any embedded HTML tags will be rendered as text. It is important to always escape inputs from untrusted sources!

Implementation note: The list of escaped characters is pulled from Svelte.

Example

let html = Container::default()
    .with_paragraph(escape_html("My <p> element!"))
    .to_html_string();

assert_eq!(html, "<div><p>My &lt;p&gt; element!</p></div>");