From 39c5b9e02f54e1316df8a0be87e8378ca5be9f03 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 21 Nov 2025 15:05:41 +0100 Subject: [PATCH] Ignore empty text nodes when searching for existing paragraphs See https://www.woltlab.com/community/thread/314964/ --- .../input/node/HtmlInputNodeProcessor.class.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 813ba10ea5..06a603bf0d 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 @@ -351,11 +351,19 @@ protected function fixDom() } } - $appendToPreviousParagraph = static function ($node) { - /** @var \DOMElement $paragraph */ - $paragraph = $node->previousSibling; + $appendToPreviousParagraph = static function (\DOMNode $node) { + $paragraph = $node; + while ($paragraph = $paragraph->previousSibling) { + if ($paragraph instanceof \DOMText) { + if (!\str_contains($paragraph->textContent, ' ') && StringUtil::trim($paragraph->textContent) === '') { + continue; + } + } + + break; + } - if (!$paragraph || $paragraph->nodeName !== 'p') { + if ($paragraph === null || $paragraph->nodeName !== 'p') { $paragraph = $node->ownerDocument->createElement('p'); $node->parentNode->insertBefore($paragraph, $node); }