From: Cyperghost Date: Mon, 22 Jan 2024 11:24:30 +0000 (+0100) Subject: Add some checks if multiply links in the same paragraph X-Git-Tag: 6.0.7_dev_1~7^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cd62bd7c6b3aaff56e739bde4407b159afefc9f7;p=GitHub%2FWoltLab%2FWCF.git Add some checks if multiply links in the same paragraph --- 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,