Unify the clean up of trailing `<br>` in `<p>` and `<td>`
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 10:09:07 +0000 (12:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 16:34:04 +0000 (18:34 +0200)
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php

index d6c3437958ed7b2d4c8ec0aaa89ecff2eaf71b9d..cb59e84d055e1cab22ea660838fcc4420bb8b6bb 100644 (file)
@@ -132,16 +132,20 @@ final class HtmlOutputNodeNormalizer
 
     private function removeTrailingBr(\DOMElement $br): void
     {
-        $paragraph = DOMUtil::closest($br, "p");
-        if ($paragraph === null) {
-            return;
+        $paragraphOrTableCell = DOMUtil::closest($br, "p");
+        if ($paragraphOrTableCell === null) {
+            $paragraphOrTableCell = DOMUtil::closest($br, "td");
+
+            if ($paragraphOrTableCell === null) {
+                return;
+            }
         }
 
-        if (!DOMUtil::isLastNode($br, $paragraph)) {
+        if (!DOMUtil::isLastNode($br, $paragraphOrTableCell)) {
             return;
         }
 
-        if ($paragraph->childNodes->length > 1) {
+        if ($paragraphOrTableCell->nodeName === "td" || $paragraphOrTableCell->childNodes->length > 1) {
             $br->remove();
         }
     }