Skip to main content

escape_for_script_block

Function escape_for_script_block 

Source
pub fn escape_for_script_block(json_ld: &str) -> String
Expand description

Escape a JSON-LD string for embedding inside <script type="application/ld+json">.

Replaces every literal < with the JSON unicode escape <. The HTML parser scans raw bytes for </script — by eliminating all < bytes we guarantee no end-tag can form. JSON-LD parsers decode < back to < natively, so document semantics are preserved.