mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:58:12 +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:
parent
6d150df58a
commit
b083a233d8
15 changed files with 158 additions and 25 deletions
|
@ -29,6 +29,23 @@ StyleResolver& Document::style_resolver()
|
|||
return *m_style_resolver;
|
||||
}
|
||||
|
||||
bool Document::is_child_allowed(const Node& node) const
|
||||
{
|
||||
switch (node.type()) {
|
||||
case NodeType::DOCUMENT_NODE:
|
||||
case NodeType::TEXT_NODE:
|
||||
return false;
|
||||
case NodeType::COMMENT_NODE:
|
||||
return true;
|
||||
case NodeType::DOCUMENT_TYPE_NODE:
|
||||
return !first_child_of_type<DocumentType>();
|
||||
case NodeType::ELEMENT_NODE:
|
||||
return !first_child_of_type<Element>();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Document::fixup()
|
||||
{
|
||||
if (!is<DocumentType>(first_child()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue