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

32
LibHTML/Parser.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <LibHTML/Element.h>
#include <LibHTML/Parser.h>
#include <LibHTML/Text.h>
static Retained<Element> create_element(const String& tag_name)
{
return adopt(*new Element(tag_name));
}
Retained<Document> parse(const String& html)
{
auto doc = adopt(*new Document);
auto head = create_element("head");
auto title = create_element("title");
auto title_text = adopt(*new Text("Page Title"));
title->append_child(title_text);
head->append_child(title);
doc->append_child(head);
auto body = create_element("body");
auto h1 = create_element("h1");
auto h1_text = adopt(*new Text("Hello World!"));
h1->append_child(h1_text);
body->append_child(h1);
doc->append_child(body);
return doc;
}