mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb: Only show namespace if non-default in DOM tree dump
When dumping the DOM tree, only prefix the element's local name with its short namespace identifier if it's not the document's default namespace. This gets rid of the excessive "html:" and "svg:" prefixes in context of an HTML or SVG document, respectively.
This commit is contained in:
parent
ae4aa2eeb0
commit
4e51e585a2
Notes:
github-actions[bot]
2025-07-18 09:56:02 +00:00
Author: https://github.com/gmta
Commit: 4e51e585a2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5499
Reviewed-by: https://github.com/AtkinsSJ ✅
1 changed files with 7 additions and 7 deletions
|
@ -95,20 +95,20 @@ void dump_tree(StringBuilder& builder, DOM::Node const& node)
|
|||
for (int i = 0; i < indent; ++i)
|
||||
builder.append(" "sv);
|
||||
if (auto const* element = as_if<DOM::Element>(node)) {
|
||||
auto short_namespace = [&] -> FlyString {
|
||||
auto namespace_prefix = [&] -> FlyString {
|
||||
auto const& namespace_uri = element->namespace_uri();
|
||||
if (!namespace_uri.has_value())
|
||||
return "n/a"_fly_string;
|
||||
if (!namespace_uri.has_value() || node.document().is_default_namespace(namespace_uri.value().to_string()))
|
||||
return ""_fly_string;
|
||||
if (namespace_uri == Namespace::HTML)
|
||||
return "html"_fly_string;
|
||||
return "html:"_fly_string;
|
||||
if (namespace_uri == Namespace::SVG)
|
||||
return "svg"_fly_string;
|
||||
return "svg:"_fly_string;
|
||||
if (namespace_uri == Namespace::MathML)
|
||||
return "mathml"_fly_string;
|
||||
return "mathml:"_fly_string;
|
||||
return *namespace_uri;
|
||||
}();
|
||||
|
||||
builder.appendff("<{}:{}", short_namespace, element->local_name());
|
||||
builder.appendff("<{}{}", namespace_prefix, element->local_name());
|
||||
element->for_each_attribute([&](auto& name, auto& value) {
|
||||
builder.appendff(" {}={}", name, value);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue