Improve support for non-HTML namespace

This does a better job of tracking the implicit namespace based on the context.
For example, when using DOMParser.parseFromString with an XML namespace, all
subsequent elements will be in the XML namespace.

Adds support for null namespace.

Rather than defaulting to HTML, unknown namespaces now map to a special unknown
type. We don't currently preserve the original namespace, but we're at least
able to properly handle the casing in this case.
This commit is contained in:
Karl Seguin
2026-01-08 20:38:23 +08:00
parent 0db1ceaea7
commit 9d498fa069
11 changed files with 736 additions and 703 deletions

View File

@@ -443,9 +443,9 @@ pub fn createContextualFragment(self: *const Range, html: []const u8, page: *Pag
// Create a temporary element of the same type as the context for parsing
// This preserves the parsing context without modifying the original node
const temp_node = if (context_node.is(Node.Element)) |el|
try page.createElement(el._namespace.toUri(), el.getTagNameLower(), null)
try page.createElementNS(el._namespace, el.getTagNameLower(), null)
else
try page.createElement(null, "div", null);
try page.createElementNS(.html, "div", null);
try page.parseHtmlAsChildren(temp_node, html);