mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +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
|
@ -1,23 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibHTML/DOM/Node.h>
|
||||
#include <LibHTML/DOM/CharacterData.h>
|
||||
|
||||
class Text final : public Node {
|
||||
class Text final : public CharacterData {
|
||||
public:
|
||||
explicit Text(Document&, const String&);
|
||||
virtual ~Text() override;
|
||||
|
||||
const String& data() const { return m_data; }
|
||||
|
||||
virtual String tag_name() const override { return "#text"; }
|
||||
|
||||
virtual String text_content() const override { return m_data; }
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
|
||||
|
||||
String m_data;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue