From b6939c803500c49d976b7041d3c19d0657ace09e Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Tue, 3 Dec 2024 19:30:55 +0100 Subject: [PATCH] LibWeb: Use wrap algorithm in "fix disallowed ancestors" We have the wrap algorithm implemented now, so resolve the FIXME. --- Libraries/LibWeb/Editing/Internal/Algorithms.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index 187e480d33..3005dca30e 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -483,9 +483,21 @@ void fix_disallowed_ancestors_of_node(GC::Ref node) ancestor = ancestor->parent(); } while (ancestor); if (!allowed_child_of_any_ancestor) { - // FIXME: 1. If node is a dd or dt, wrap the one-node list consisting of node, with sibling criteria returning true for + // 1. If node is a dd or dt, wrap the one-node list consisting of node, with sibling criteria returning true for // any dl with no attributes and false otherwise, and new parent instructions returning the result of calling // createElement("dl") on the context object. Then abort these steps. + if (is(*node) && static_cast(*node).local_name().is_one_of(HTML::TagNames::dd, HTML::TagNames::dt)) { + wrap( + { node }, + [](GC::Ref sibling) { + if (!is(*sibling)) + return false; + auto& sibling_element = static_cast(*sibling); + return sibling_element.local_name() == HTML::TagNames::dl && !sibling_element.has_attributes(); + }, + [&node] { return MUST(DOM::create_element(node->document(), HTML::TagNames::dl, Namespace::HTML)); }); + return; + } // 2. If "p" is not an allowed child of the editing host of node, abort these steps. if (!is_allowed_child_of_node(HTML::TagNames::p, GC::Ref { *editing_host_of_node(*node) }))