Fix the handling of strikethrough applied to inline code
authorAlexander Ebert <ebert@woltlab.com>
Tue, 1 Aug 2023 11:26:16 +0000 (13:26 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 1 Aug 2023 11:26:16 +0000 (13:26 +0200)
See https://www.woltlab.com/community/thread/300926-code-not-strikethroughed-in-the-new-editor/

wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeKbd.class.php

index 36de21ef898ebf9b7dd33eb30682d8a44deadff1..ead4bcc562a9c7223e2bd456ae0d71ecf9e3d84b 100644 (file)
@@ -49,6 +49,13 @@ class HtmlInputNodeKbd extends AbstractHtmlInputNode
             }
 
             if ($containsElements) {
+                // Check if the *entire* content is striked through and wrap it.
+                $isStrikedThrough = false;
+                $strikethroughs = $htmlNodeProcessor->getXPath()->query("./s", $element);
+                if ($strikethroughs->length === 1 && $strikethroughs->item(0)->textContent === $element->textContent) {
+                    $isStrikedThrough = true;
+                }
+
                 $newElement = $element->ownerDocument->createElement('kbd');
                 $newElement->appendChild(
                     $element->ownerDocument->createTextNode(
@@ -57,6 +64,12 @@ class HtmlInputNodeKbd extends AbstractHtmlInputNode
                 );
 
                 DOMUtil::replaceElement($element, $newElement, false);
+
+                if ($isStrikedThrough) {
+                    $strikethrough = $newElement->ownerDocument->createElement("s");
+                    $newElement->parentNode->insertBefore($strikethrough, $newElement);
+                    $strikethrough->append($newElement);
+                }
             }
         }
     }