Fix the detection of `<p><br></p>`
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 16:20:44 +0000 (18:20 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 May 2023 16:34:04 +0000 (18:34 +0200)
ts/WoltLabSuite/Core/Component/Ckeditor/Cleanup.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Cleanup.js

index cb7f75c273e5bf1be713cfdf4fde5a40fa7f33e2..9b6447c6460496f13f3829e2e9bb7b0f3ba342fa 100644 (file)
@@ -70,9 +70,11 @@ function getPossibleSpacerParagraphs(div: HTMLElement): HTMLParagraphElement[] {
   const paragraphs: HTMLParagraphElement[] = [];
 
   div.querySelectorAll("p").forEach((paragraph) => {
-    if (paragraph.childElementCount === 1) {
-      const child = paragraph.children[0] as HTMLElement;
-      if (child.tagName === "BR" && child.dataset.ckeFiller !== "true") {
+    paragraph.normalize();
+
+    if (paragraph.childNodes.length === 1) {
+      const child = paragraph.childNodes[0];
+      if (child instanceof HTMLBRElement && child.dataset.ckeFiller !== "true") {
         paragraphs.push(paragraph);
       }
     }
index ccbe5f0a337abd92ec450d1eefd3be81ee5b456a..46f0f41c68b1ae5eae90cdaaa5e1d8f956b3a505 100644 (file)
@@ -63,9 +63,10 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp
     function getPossibleSpacerParagraphs(div) {
         const paragraphs = [];
         div.querySelectorAll("p").forEach((paragraph) => {
-            if (paragraph.childElementCount === 1) {
-                const child = paragraph.children[0];
-                if (child.tagName === "BR" && child.dataset.ckeFiller !== "true") {
+            paragraph.normalize();
+            if (paragraph.childNodes.length === 1) {
+                const child = paragraph.childNodes[0];
+                if (child instanceof HTMLBRElement && child.dataset.ckeFiller !== "true") {
                     paragraphs.push(paragraph);
                 }
             }