File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -82,9 +82,13 @@ pub fn writeNode(node: *parser.Node, writer: anytype) anyerror!void {
8282 // void elements can't have any content.
8383 if (try isVoid (parser .nodeToElement (node ))) return ;
8484
85- // write the children
86- // TODO avoid recursion
87- try writeChildren (node , writer );
85+ if (try parser .elementHTMLGetTagType (@ptrCast (node )) == .script ) {
86+ try writer .writeAll (try parser .nodeTextContent (node ) orelse "" );
87+ } else {
88+ // write the children
89+ // TODO avoid recursion
90+ try writeChildren (node , writer );
91+ }
8892
8993 // close the tag
9094 try writer .writeAll ("</" );
@@ -211,6 +215,11 @@ test "dump.writeHTML" {
211215 \\</head><body>9000</body></html>
212216 \\
213217 , "<html><title>It's over what?</title><meta name=a value=\" b\" >\n <body>9000" );
218+
219+ try testWriteHTML (
220+ "<p>hi</p><script>alert(power > 9000)</script>" ,
221+ "<p>hi</p><script>alert(power > 9000)</script>" ,
222+ );
214223}
215224
216225fn testWriteHTML (comptime expected_body : []const u8 , src : []const u8 ) ! void {
You can’t perform that action at this time.
0 commit comments