From cd62bd7c6b3aaff56e739bde4407b159afefc9f7 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Mon, 22 Jan 2024 12:24:30 +0100 Subject: [PATCH] Add some checks if multiply links in the same paragraph --- .../html/node/HtmlNodePlainLink.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php b/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php index dd178e67bc..3d949e9d52 100644 --- a/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php +++ b/wcfsetup/install/files/lib/system/html/node/HtmlNodePlainLink.class.php @@ -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, -- 2.20.1