diff options
author | gennyble <gen@nyble.dev> | 2023-12-27 16:22:02 -0600 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2023-12-27 16:22:02 -0600 |
commit | 54dec82cb8620937306e9a16b4b532cb52c7ee55 (patch) | |
tree | acf1efa8441644962487189ae98bf6185aed5bfe | |
parent | 80ee85dca7f36db8d968c67cbd1d552f98d534f9 (diff) | |
download | cutie-54dec82cb8620937306e9a16b4b532cb52c7ee55.tar.gz cutie-54dec82cb8620937306e9a16b4b532cb52c7ee55.zip |
parse external scripts
-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)] |