mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
27 lines
720 B
C++
27 lines
720 B
C++
|
#include <LibHTML/Document.h>
|
||
|
#include <LibHTML/Dump.h>
|
||
|
#include <LibHTML/Element.h>
|
||
|
#include <LibHTML/Text.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
void dump_tree(Node& node)
|
||
|
{
|
||
|
static int indent = 0;
|
||
|
for (int i = 0; i < indent; ++i)
|
||
|
printf(" ");
|
||
|
if (node.is_document()) {
|
||
|
printf("*Document*\n");
|
||
|
} else if (node.is_element()) {
|
||
|
printf("<%s>\n", static_cast<Element&>(node).tag_name().characters());
|
||
|
} else if (node.is_text()) {
|
||
|
printf("\"%s\"\n", static_cast<Text&>(node).data().characters());
|
||
|
}
|
||
|
++indent;
|
||
|
if (node.is_parent_node()) {
|
||
|
static_cast<ParentNode&>(node).for_each_child([](Node& child) {
|
||
|
dump_tree(child);
|
||
|
});
|
||
|
}
|
||
|
--indent;
|
||
|
}
|