Skip to content

Commit 39c5b9e

Browse files
committed
Ignore empty text nodes when searching for existing paragraphs
See https://www.woltlab.com/community/thread/314964/
1 parent d5afa23 commit 39c5b9e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,19 @@ protected function fixDom()
351351
}
352352
}
353353

354-
$appendToPreviousParagraph = static function ($node) {
355-
/** @var \DOMElement $paragraph */
356-
$paragraph = $node->previousSibling;
354+
$appendToPreviousParagraph = static function (\DOMNode $node) {
355+
$paragraph = $node;
356+
while ($paragraph = $paragraph->previousSibling) {
357+
if ($paragraph instanceof \DOMText) {
358+
if (!\str_contains($paragraph->textContent, ' ') && StringUtil::trim($paragraph->textContent) === '') {
359+
continue;
360+
}
361+
}
362+
363+
break;
364+
}
357365

358-
if (!$paragraph || $paragraph->nodeName !== 'p') {
366+
if ($paragraph === null || $paragraph->nodeName !== 'p') {
359367
$paragraph = $node->ownerDocument->createElement('p');
360368
$node->parentNode->insertBefore($paragraph, $node);
361369
}

0 commit comments

Comments
 (0)