Clean-up `<kbd>`
authorAlexander Ebert <ebert@woltlab.com>
Thu, 29 Sep 2016 14:15:36 +0000 (16:15 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 29 Sep 2016 14:15:36 +0000 (16:15 +0200)
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeKbd.class.php [new file with mode: 0644]
wcfsetup/install/files/style/bbcode/inlineCode.scss

diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeKbd.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeKbd.class.php
new file mode 100644 (file)
index 0000000..0463bf2
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+namespace wcf\system\html\input\node;
+use wcf\system\html\node\AbstractHtmlNodeProcessor;
+use wcf\util\DOMUtil;
+use wcf\util\StringUtil;
+
+/**
+ * Processes `<kbd>` and ensures that they only contain raw text.
+ *
+ * @author      Alexander Ebert
+ * @copyright   2001-2016 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package     WoltLabSuite\Core\System\Html\Input\Node
+ * @since       3.0
+ */
+class HtmlInputNodeKbd extends AbstractHtmlInputNode {
+       /**
+        * @inheritDoc
+        */
+       protected $tagName = 'kbd';
+       
+       /**
+        * @inheritDoc
+        */
+       public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) {
+               return [];
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
+               /** @var \DOMElement $element */
+               foreach ($elements as $element) {
+                       if (DOMUtil::isRemoved($element) || !$element->parentNode) {
+                               continue;
+                       }
+                       
+                       $containsElements = false;
+                       for ($i = 0, $length = $element->childNodes->length; $i < $length; $i++) {
+                               if ($element->childNodes->item($i)->nodeType !== XML_TEXT_NODE) {
+                                       $containsElements = true;
+                                       break;
+                               }
+                       }
+                       
+                       if ($containsElements) {
+                               $newElement = $element->ownerDocument->createElement('kbd');
+                               $newElement->appendChild(
+                                       $element->ownerDocument->createTextNode(
+                                               StringUtil::trim($element->textContent)
+                                       )
+                               );
+                               
+                               DOMUtil::replaceElement($element, $newElement, false);
+                       }
+               }
+       }
+}
index e81d840cd00969b49ebeb5165ab53dd102669632..a5dcb2c7a574ebc3467a216fb4bb892cbbdf583c 100644 (file)
@@ -6,9 +6,12 @@ kbd {
        color: rgba(68, 68, 68, 1) !important;
        display: inline-block;
        font-family: Consolas, 'Courier New', monospace;
+       font-style: normal;
+       font-weight: normal;
        margin: 0 2px;
        overflow: auto;
        padding: 0 4px;
+       text-decoration: none;
        vertical-align: middle;
        word-break: break-all;
        word-wrap: break-word;