mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Merge pull request #1762 from lightpanda-io/xml_get_elements_by_tag_name
Node matching using tag name string comparison on non-HTML nodes
This commit is contained in:
@@ -397,3 +397,25 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script id=getElementsByTagName-xml>
|
||||
{
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString('<layout><row><col>A</col><col>B</col></row></layout>', 'text/xml');
|
||||
|
||||
// Test getElementsByTagName on document
|
||||
const rows = doc.getElementsByTagName('row');
|
||||
testing.expectEqual(1, rows.length);
|
||||
|
||||
// Test getElementsByTagName on element
|
||||
const row = rows[0];
|
||||
const cols = row.getElementsByTagName('col');
|
||||
testing.expectEqual(2, cols.length);
|
||||
testing.expectEqual('A', cols[0].textContent);
|
||||
testing.expectEqual('B', cols[1].textContent);
|
||||
|
||||
// Test getElementsByTagName('*') on element
|
||||
const allElements = row.getElementsByTagName('*');
|
||||
testing.expectEqual(2, allElements.length);
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -219,7 +219,14 @@ pub fn NodeLive(comptime mode: Mode) type {
|
||||
switch (mode) {
|
||||
.tag => {
|
||||
const el = node.is(Element) orelse return false;
|
||||
// For HTML namespace elements, we can use the optimized tag comparison.
|
||||
// For other namespaces (XML, SVG custom elements, etc.), fall back to string comparison.
|
||||
if (el._namespace == .html) {
|
||||
return el.getTag() == self._filter;
|
||||
}
|
||||
// For non-HTML elements, compare by tag name string
|
||||
const element_tag = el.getTagNameLower();
|
||||
return std.mem.eql(u8, element_tag, @tagName(self._filter));
|
||||
},
|
||||
.tag_name => {
|
||||
// If we're in `tag_name` mode, then the tag_name isn't
|
||||
|
||||
Reference in New Issue
Block a user