Avoid empty <p /> generated after non-<p> block elements
authorAlexander Ebert <ebert@woltlab.com>
Mon, 9 Oct 2017 15:42:29 +0000 (17:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 9 Oct 2017 15:42:29 +0000 (17:42 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index 1d7abc18e22d64f575abbbe47662ebc9c2921dfc..2fc4735c7862351a70da1ece800e9f854671caf1 100644 (file)
@@ -224,20 +224,20 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor {
                
                /** @var \DOMNode $node */
                $node = $this->getDocument()->getElementsByTagName('body')->item(0)->firstChild;
-               $hX = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
                while ($node) {
                        if ($node->nodeType === XML_ELEMENT_NODE && $node->nodeName === 'woltlab-metacode-marker') {
                                $node = $appendToPreviousParagraph($node);
                        }
                        else if ($node->nodeType === XML_TEXT_NODE) {
+                               // text node contains only a line break
                                if ($node->textContent === "\n" || $node->textContent === "\r\n") {
-                                       $sibling = $node->previousSibling;
-                                       if ($sibling !== null && in_array($sibling->nodeName, $hX)) {
-                                               // ignore this node entirely
+                                       // check if the previous node is a <p>, otherwise ignore this node entirely
+                                       if ($node->previousSibling === null || $node->previousSibling->nodeName !== 'p') {
                                                $node = $node->nextSibling;
                                                continue;
                                        }
                                }
+                               
                                $node = $appendToPreviousParagraph($node);
                        }