From: Alexander Ebert Date: Thu, 4 May 2023 14:06:55 +0000 (+0200) Subject: Strip extra paragraph elements that were created in earlier versions X-Git-Tag: 6.0.0_Alpha_1~136^2~17 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=1a629474088bcfefceeb465d71e058a512866be9;p=GitHub%2FWoltLab%2FWCF.git Strip extra paragraph elements that were created in earlier versions --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeP.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeP.class.php new file mode 100644 index 0000000000..8f333815aa --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeP.class.php @@ -0,0 +1,44 @@ + + * @since 6.0 + */ +final class HtmlOutputNodeP extends AbstractHtmlOutputNode +{ + /** + * @inheritDoc + */ + protected $tagName = 'p'; + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) + { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + if ($element->childElementCount === 1 && $element->firstElementChild) { + $child = $element->firstElementChild; + if ($child->tagName === 'br' && $child->getAttribute('data-cke-filler') !== 'true') { + // This is most likely a legacy paragraph that was inserted + // in earlier versions and is not longer required. We need + // to verify that there is no other text inside the node + // before removing it. + if (StringUtil::trim($element->textContent) === '') { + $element->remove(); + } + } + } + } + } +}