From 1a629474088bcfefceeb465d71e058a512866be9 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 4 May 2023 16:06:55 +0200 Subject: [PATCH] Strip extra paragraph elements that were created in earlier versions --- .../output/node/HtmlOutputNodeP.class.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeP.class.php 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(); + } + } + } + } + } +} -- 2.20.1