Add some checks if multiply links in the same paragraph
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 22 Jan 2024 11:24:30 +0000 (12:24 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 22 Jan 2024 11:24:30 +0000 (12:24 +0100)
wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php

index dd178e67bc720e07c9e977ed760ae16a091305f9..3d949e9d52183e3bd01e96b87aaf3b34bf4a60f6 100644 (file)
@@ -185,6 +185,16 @@ class HtmlNodePlainLink
                 $parent = $this->link;
                 $next = $this->findBr($this->link, 'nextSibling');
                 $previous = $this->findBr($this->link, 'previousSibling');
+
+                // If multiple links are in the same paragraph, the `topLevelParent` link to old parent in the DOM
+                // and have to be found again.
+                if ($this->topLevelParent->parentElement === null) {
+                    $this->topLevelParent = $this->link;
+                    while ($this->topLevelParent->parentNode->nodeName !== 'body') {
+                        $this->topLevelParent = $this->topLevelParent->parentNode;
+                    }
+                }
+
                 // Link inside other elements(u, i, b, …)
                 while ($next === null && $previous === null && $parent !== $this->topLevelParent) {
                     $parent = $parent->parentElement;
@@ -192,6 +202,15 @@ class HtmlNodePlainLink
                     $previous = $this->findBr($parent, 'previousSibling');
                 }
 
+                // Link is the only content in the top level parent.
+                // This will happen, when in one paragraph are multiple links.
+                if ($next === null && $previous === null) {
+                    $this->topLevelParent->parentNode->insertBefore($this->link, $this->topLevelParent);
+                    DOMUtil::removeNode($this->topLevelParent);
+                    DOMUtil::replaceElement($this->link, $metacodeElement, false);
+                    return;
+                }
+
                 if ($next !== null) {
                     $replaceNode = DOMUtil::splitParentsUntil(
                         $parent,