From: Alexander Ebert Date: Tue, 4 Apr 2023 16:23:11 +0000 (+0200) Subject: Preserve empty paragraphs created in CKEditor 5 X-Git-Tag: 6.0.0_Alpha_1~294^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=77447b4aa3ecdc1e752c82e9d2e596d9eb6d9d47;p=GitHub%2FWoltLab%2FWCF.git Preserve empty paragraphs created in CKEditor 5 Fixes WoltLab/editor#15 --- 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; }