1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibWeb: Implement HTML fragment serialisation and use it in innerHTML

The previous implementation was about a half implementation and was
tied to Element::innerHTML. This separates it and puts it into
HTMLDocumentParser, as this is in the parsing section of the spec.

This provides a near finished HTML fragment serialisation algorithm,
bar namespaces in attributes and the `is` value.
This commit is contained in:
Luke Wilde 2021-09-13 22:42:15 +01:00 committed by Andreas Kling
parent ed5128d759
commit f62477c093
6 changed files with 233 additions and 54 deletions

View file

@ -24,6 +24,7 @@
#include <LibWeb/DOM/ProcessingInstruction.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TextNode.h>
@ -768,6 +769,18 @@ void Node::string_replace_all(String const& string)
replace_all(node);
}
// https://w3c.github.io/DOM-Parsing/#dfn-fragment-serializing-algorithm
String Node::serialize_fragment(/* FIXME: Requires well-formed flag */) const
{
// FIXME: Let context document be the value of node's node document.
// FIXME: If context document is an HTML document, return an HTML serialization of node.
// (We currently always do this)
return HTML::HTMLDocumentParser::serialize_html_fragment(*this);
// FIXME: Otherwise, context document is an XML document; return an XML serialization of node passing the flag require well-formed.
}
// https://dom.spec.whatwg.org/#dom-node-issamenode
bool Node::is_same_node(Node const* other_node) const
{