Skip to main content

strip_script_and_style

Function strip_script_and_style 

Source
pub fn strip_script_and_style(html: &str) -> String
Expand description

Returns a copy of html with the contents of every <script> and <style> element blanked to spaces (byte offsets are preserved; newlines survive so line-based diagnostics stay stable).

Tag-scanning gates use this so markup embedded in JS string literals — e.g. a client-side search overlay building <a href="…"> result rows — is never mistaken for document links.

§Examples

use ssg::audit::gates::strip_script_and_style;
let html = r#"<script>var s='<a href="/x">';</script><a href="/y">y</a>"#;
let stripped = strip_script_and_style(html);
assert!(!stripped.contains("/x"));
assert!(stripped.contains("/y"));