1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-05 08:17:36 +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:
Andreas Kling 2019-06-15 18:55:47 +02:00
parent 01d1aee922
commit a67e823838
19 changed files with 329 additions and 0 deletions

26
LibHTML/Dump.cpp Normal file
View 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;
}