Preventing trailing <br>
authorAlexander Ebert <ebert@woltlab.com>
Thu, 11 Aug 2016 20:11:46 +0000 (22:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 11 Aug 2016 20:11:46 +0000 (22:11 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php

index b34e21f657c811badecef0a256cc17df828c5acf..c3402703c2dbe043c98ffa6c4255572b30d621ed 100644 (file)
@@ -50,9 +50,28 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor {
                        while ($paragraphs->length) {
                                $paragraph = $paragraphs->item(0);
                                
-                               for ($i = 0; $i < 2; $i++) {
-                                       $br = $this->getDocument()->createElement('br');
-                                       $paragraph->appendChild($br);
+                               $isLastNode = true;
+                               $sibling = $paragraph;
+                               while ($sibling = $sibling->nextSibling) {
+                                       if ($sibling->nodeType === XML_ELEMENT_NODE) {
+                                               if ($sibling->nodeName !== 'br') {
+                                                       $isLastNode = false;
+                                                       break;
+                                               }
+                                       }
+                                       else if ($sibling->nodeType === XML_TEXT_NODE) {
+                                               if (StringUtil::trim($sibling->textContent) !== '') {
+                                                       $isLastNode = false;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               
+                               if (!$isLastNode) {
+                                       for ($i = 0; $i < 2; $i++) {
+                                               $br = $this->getDocument()->createElement('br');
+                                               $paragraph->appendChild($br);
+                                       }
                                }
                                
                                DOMUtil::removeNode($paragraph, true);