From 6ebb0298efe1b2d419aa4eb9a86254fd5366b18f Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 3 Oct 2026 23:57:09 +0000 Subject: [PATCH 1/2] Don't escape raw text when serializing only an element's children With include_self=False, serialize passed TraversalScope::ChildrenOnly without the parent element's name. html5ever's serializer uses that name to decide whether the children are raw text, so the contents of

a < b

", + markupever.HtmlOptions(full_document=False), + ) + script, style, p = dom.root().children() + assert script.serialize(indent=0, include_self=False) == "if (a < b && c) {}" + assert style.serialize(indent=0, include_self=False) == "a > b { }" + assert p.serialize(indent=0, include_self=False) == "a < b" diff --git a/src/parser.rs b/src/parser.rs index f563b18..4f9c003 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -485,7 +485,16 @@ pub fn serialize( let traversal_scope = if include_self { ::treedom::markup5ever::serialize::TraversalScope::IncludeNode } else { - ::treedom::markup5ever::serialize::TraversalScope::ChildrenOnly(None) + // The serializer needs the parent's name to know whether its text + // children are raw text (as in