diff options
-rw-r--r-- | src/lib.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs index 55eba4b..26ec5dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,9 @@ impl Html { loop { // Special case <script> and <style> - if root_tag.name == "script" || root_tag.name == "style" { + if root_tag.name == "script" && tag.get_attribute("src").is_none() + || root_tag.name == "style" + { let special = Self::special_parse(rest.unwrap(), root_tag.name); match special { @@ -491,6 +493,42 @@ mod test { vec![tag!("p", [text!("Hello ")]), tag!("p", [text!("World!")])] ) } + + #[test] + fn parse_script() { + let raw = "<head>\n\t<script>let k=\"v\";\n\t</script>\n</head>"; + + let hh = Html::parse(raw); + assert_eq!( + hh.nodes, + vec![tag!( + "head", + [ + text!("\n\t"), + tag!("script", [text!("let k=\"v\";\n\t")]), + text!("\n") + ] + )] + ) + } + + #[test] + fn parse_external_script() { + let raw = "<head>\n\t<script src=\"script.js\"></script>\n</head>"; + + let hh = Html::parse(raw); + assert_eq!( + hh.nodes, + vec![tag!( + "head", + [ + text!("\n\t"), + tag!("script", "src=\"script.js\""), + text!("\n") + ] + )] + ) + } } #[cfg(test)] |