From 4e51e585a2f20125d92f22b19124e4c9897655bd Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 18 Jul 2025 10:07:03 +0200 Subject: [PATCH] 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. --- Libraries/LibWeb/Dump.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Libraries/LibWeb/Dump.cpp b/Libraries/LibWeb/Dump.cpp index fb698dd65dc..e01736ada37 100644 --- a/Libraries/LibWeb/Dump.cpp +++ b/Libraries/LibWeb/Dump.cpp @@ -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(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); });