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

LibWeb: Fully implement the fragment serializing algorithm

Rather than assuming the node's node document is an HTML document,
handle XML documents as well.
This commit is contained in:
Timothy Flynn 2022-11-02 19:14:27 -04:00 committed by Linus Groh
parent e1ac9c83b2
commit 13b8eeff54
7 changed files with 19 additions and 13 deletions

View file

@ -1173,15 +1173,17 @@ void Node::string_replace_all(String const& string)
}
// https://w3c.github.io/DOM-Parsing/#dfn-fragment-serializing-algorithm
String Node::serialize_fragment(/* FIXME: Requires well-formed flag */) const
WebIDL::ExceptionOr<String> Node::serialize_fragment(DOMParsing::RequireWellFormed require_well_formed) const
{
// FIXME: 1. Let context document be the value of node's node document.
// 1. Let context document be the value of node's node document.
auto const& context_document = document();
// FIXME: 2. If context document is an HTML document, return an HTML serialization of node.
// (We currently always do this)
return HTML::HTMLParser::serialize_html_fragment(*this);
// 2. If context document is an HTML document, return an HTML serialization of node.
if (context_document.is_html_document())
return HTML::HTMLParser::serialize_html_fragment(*this);
// FIXME: 3. Otherwise, context document is an XML document; return an XML serialization of node passing the flag require well-formed.
// 3. Otherwise, context document is an XML document; return an XML serialization of node passing the flag require well-formed.
return DOMParsing::serialize_node_to_xml_string(*this, require_well_formed);
}
// https://dom.spec.whatwg.org/#dom-node-issamenode