mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 00:25:12 +00:00
LibHTML: Start working on a simple HTML library.
I'd like to have rich text, and we might as well use HTML for that. :^)
This commit is contained in:
26
LibHTML/Dump.cpp
Normal file
26
LibHTML/Dump.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user