LibWeb: Improve DOM dump formatting for HTML template elements

Let's dump both the template contents, and any DOM nodes inside the
template element itself, since both are valid states produced by the
HTML parser.
This commit is contained in:
Andreas Kling 2025-04-25 09:35:30 +02:00 committed by Andreas Kling
commit 1102a31866
Notes: github-actions[bot] 2025-04-25 09:02:16 +00:00

View file

@ -125,16 +125,19 @@ void dump_tree(StringBuilder& builder, DOM::Node const& node)
}
}
}
if (is<HTML::HTMLTemplateElement>(node)) {
auto& template_element = as<HTML::HTMLTemplateElement>(node);
for (int i = 0; i < indent; ++i)
builder.append(" "sv);
builder.append("(template content)\n"sv);
dump_tree(builder, template_element.content());
builder.append("(template normal subtree)\n"sv);
}
if (is<DOM::ParentNode>(node)) {
if (!is<HTML::HTMLTemplateElement>(node)) {
static_cast<DOM::ParentNode const&>(node).for_each_child([&](auto& child) {
dump_tree(builder, child);
return IterationDecision::Continue;
});
} else {
auto& template_element = as<HTML::HTMLTemplateElement>(node);
dump_tree(builder, template_element.content());
}
static_cast<DOM::ParentNode const&>(node).for_each_child([&](auto& child) {
dump_tree(builder, child);
return IterationDecision::Continue;
});
}
--indent;
}