diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-02 14:53:38 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-02 14:53:38 +0100 |
commit | 0ff07980aeda5b26a82b7689b1cf4ba1085aded2 (patch) | |
tree | 51b26a3613a063721aa5f631caac3925087e57e3 /Libraries/LibHTML | |
parent | ffcd395afc144b7790118b0e3db40a62c43cb6fd (diff) | |
download | serenity-0ff07980aeda5b26a82b7689b1cf4ba1085aded2.zip |
LibHTML: Include element attributes in the DOMTreeModel
We simply expand the attributes inside the element item name, so they
look like natural "tags" :^)
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r-- | Libraries/LibHTML/DOMTreeModel.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/Libraries/LibHTML/DOMTreeModel.cpp b/Libraries/LibHTML/DOMTreeModel.cpp index 61df349c9d..d20647f75c 100644 --- a/Libraries/LibHTML/DOMTreeModel.cpp +++ b/Libraries/LibHTML/DOMTreeModel.cpp @@ -1,6 +1,7 @@ #include "DOMTreeModel.h" #include <AK/StringBuilder.h> #include <LibHTML/DOM/Document.h> +#include <LibHTML/DOM/Element.h> #include <LibHTML/DOM/Text.h> #include <ctype.h> #include <stdio.h> @@ -88,20 +89,34 @@ static String with_whitespace_collapsed(const StringView& string) GVariant DOMTreeModel::data(const GModelIndex& index, Role role) const { - auto* node = static_cast<Node*>(index.internal_data()); + auto& node = *static_cast<Node*>(index.internal_data()); if (role == Role::Icon) { - if (node->is_document()) + if (node.is_document()) return m_document_icon; - if (node->is_element()) + if (node.is_element()) return m_element_icon; // FIXME: More node type icons? return m_text_icon; } if (role == Role::Display) { - if (node->is_text()) { - return String::format("%s", with_whitespace_collapsed(to<Text>(*node).data()).characters()); - } - return String::format("<%s>", node->tag_name().characters()); + if (node.is_text()) + return String::format("%s", with_whitespace_collapsed(to<Text>(node).data()).characters()); + if (!node.is_element()) + return node.tag_name(); + auto& element = to<Element>(node); + StringBuilder builder; + builder.append('<'); + builder.append(element.tag_name()); + element.for_each_attribute([&](auto& name, auto& value) { + builder.append(' '); + builder.append(name); + builder.append('='); + builder.append('"'); + builder.append(value); + builder.append('"'); + }); + builder.append('>'); + return builder.to_string(); } return {}; } |