From 77447b4aa3ecdc1e752c82e9d2e596d9eb6d9d47 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 4 Apr 2023 18:23:11 +0200 Subject: [PATCH] Preserve empty paragraphs created in CKEditor 5 Fixes WoltLab/editor#15 --- .../input/node/HtmlInputNodeProcessor.class.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index d54a500b42..e7601bccf9 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -447,6 +447,18 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor foreach ($this->getDocument()->getElementsByTagName('p') as $paragraph) { DOMUtil::normalize($paragraph); + // CKEditor 5 exports empty paragraphs as `

 

`. + if ($paragraph->childNodes->length === 1) { + $node = $paragraph->childNodes->item(0); + if ($node->nodeType === \XML_TEXT_NODE && $node->textContent === "\u{00a0}") { + $br = $node->ownerDocument->createElement("br"); + $node->parentNode->appendChild($br); + $node->parentNode->removeChild($node); + + continue; + } + } + if ($paragraph->firstChild && $paragraph->firstChild->nodeType === \XML_TEXT_NODE) { $oldNode = $paragraph->firstChild; $newNode = $paragraph->ownerDocument->createTextNode( @@ -746,6 +758,7 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor // Check if the line appears to only contain the link text. $parent = $link; while ($parent->parentNode->nodeName !== 'body') { + /** @var \DOMElement $parent */ $parent = $parent->parentNode; } -- 2.20.1