1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:38:11 +00:00

LibHTML: Add Comment and CharacterData nodes and improve HTML parsing

This patch adds the CharacterData subclass of Node, which is now the
parent class of Text and a new Comment class.

A Comment node is one of these in HTML: <!--hello friends-->
Since these occur somewhat frequently on the web, we need to be able
to parse them.

This patch also adds a child rejection mechanism to the DOM tree.
Nodes can now override is_child_allowed(Node) and return false if they
don't want a particular Node to become a child of theirs. This is used
to prevent Document from taking on unwanted children.
This commit is contained in:
Andreas Kling 2019-10-12 23:26:47 +02:00
parent 6d150df58a
commit b083a233d8
15 changed files with 158 additions and 25 deletions

View file

@ -1,5 +1,6 @@
#include <AK/Utf8View.h>
#include <LibHTML/CSS/StyleSheet.h>
#include <LibHTML/DOM/Comment.h>
#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/DocumentType.h>
#include <LibHTML/DOM/Element.h>
@ -27,6 +28,8 @@ void dump_tree(const Node& node)
dbgprintf("\"%s\"\n", static_cast<const Text&>(node).data().characters());
} else if (is<DocumentType>(node)) {
dbgprintf("<!DOCTYPE>\n");
} else if (is<Comment>(node)) {
dbgprintf("<!--%s-->\n", to<Comment>(node).data().characters());
}
++indent;
if (is<ParentNode>(node)) {