cdp: add attributes to the node's writer

This commit is contained in:
Pierre Tachoire
2025-04-30 15:56:06 +02:00
parent 09fbbc1e17
commit d2a68e62e9

View File

@@ -260,6 +260,19 @@ pub const Writer = struct {
try w.write(parent_node.id); try w.write(parent_node.id);
} }
const _map = try parser.nodeGetAttributes(n);
if (_map) |map| {
const attr_count = try parser.namedNodeMapGetLength(map);
try w.objectField("attributes");
try w.beginArray();
for (0..attr_count) |i| {
const attr = try parser.namedNodeMapItem(map, @intCast(i)) orelse continue;
try w.write(try parser.attributeGetName(attr));
try w.write(try parser.attributeGetValue(attr) orelse continue);
}
try w.endArray();
}
try w.objectField("nodeType"); try w.objectField("nodeType");
try w.write(@intFromEnum(try parser.nodeType(n))); try w.write(@intFromEnum(try parser.nodeType(n)));