mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Listen for CDATASections and ProcessingInstructions in XML docs
Using the new hooks in the XML Parser's listener interface, we now append DOM nodes for CDATASections and ProcessingInstructions to the document as they are encountered. This commit also fixes where comment nodes are appended, ensuring they are added to the current node instead of the document root.
This commit is contained in:
parent
d9976b98b9
commit
9d93d37644
|
|
@ -4,8 +4,10 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/DOM/CDATASection.h>
|
||||
#include <LibWeb/DOM/DocumentType.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/DOM/ProcessingInstruction.h>
|
||||
#include <LibWeb/HTML/HTMLTemplateElement.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
|
||||
|
|
@ -260,9 +262,28 @@ void XMLDocumentBuilder::text(StringView data)
|
|||
|
||||
void XMLDocumentBuilder::comment(StringView data)
|
||||
{
|
||||
if (m_has_error)
|
||||
if (m_has_error || !m_current_node)
|
||||
return;
|
||||
MUST(m_document->append_child(m_document->create_comment(MUST(String::from_utf8(data)))));
|
||||
|
||||
MUST(m_current_node->append_child(m_document->create_comment(MUST(String::from_utf8(data)))));
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::cdata_section(StringView data)
|
||||
{
|
||||
if (m_has_error || !m_current_node)
|
||||
return;
|
||||
|
||||
auto section = MUST(m_document->create_cdata_section(MUST(String::from_utf8(data))));
|
||||
MUST(m_current_node->append_child(section));
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::processing_instruction(StringView target, StringView data)
|
||||
{
|
||||
if (m_has_error || !m_current_node)
|
||||
return;
|
||||
|
||||
auto processing_instruction = MUST(m_document->create_processing_instruction(MUST(String::from_utf8(target)), MUST(String::from_utf8(data))));
|
||||
MUST(m_current_node->append_child(processing_instruction));
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::document_end()
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ private:
|
|||
virtual void element_end(XML::Name const& name) override;
|
||||
virtual void text(StringView data) override;
|
||||
virtual void comment(StringView data) override;
|
||||
virtual void cdata_section(StringView data) override;
|
||||
virtual void processing_instruction(StringView target, StringView data) override;
|
||||
virtual void document_end() override;
|
||||
|
||||
Optional<FlyString> namespace_for_name(XML::Name const&);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user