Avoid empty paragraphs after headlines
authorAlexander Ebert <ebert@woltlab.com>
Thu, 5 Oct 2017 11:32:02 +0000 (13:32 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 5 Oct 2017 11:32:02 +0000 (13:32 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index e36ddfb51b6196c59318385f4fc8398cde13e8b0..1d7abc18e22d64f575abbbe47662ebc9c2921dfc 100644 (file)
@@ -224,11 +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) {
+                               if ($node->textContent === "\n" || $node->textContent === "\r\n") {
+                                       $sibling = $node->previousSibling;
+                                       if ($sibling !== null && in_array($sibling->nodeName, $hX)) {
+                                               // ignore this node entirely
+                                               $node = $node->nextSibling;
+                                               continue;
+                                       }
+                               }
                                $node = $appendToPreviousParagraph($node);
                        }