From: Alexander Ebert Date: Sat, 29 Aug 2020 12:05:58 +0000 (+0200) Subject: Preserve the leading and trailing whitespace in `` on output X-Git-Tag: 5.3.0_Alpha_1~19 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=19fdb871389635ac30f33817d6d558f3976eb9de;p=GitHub%2FWoltLab%2FWCF.git Preserve the leading and trailing whitespace in `` on output Fixes #3536 --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeKbd.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeKbd.class.php new file mode 100644 index 0000000000..72152cbe5c --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeKbd.class.php @@ -0,0 +1,42 @@ + + * @package WoltLabSuite\Core\System\Html\Output\Node + * @since 5.3 + */ +class HtmlOutputNodeKbd extends AbstractHtmlOutputNode { + /** + * @inheritDoc + */ + protected $tagName = 'kbd'; + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $textContent = $element->textContent; + + if (mb_strlen($textContent) !== 0) { + if ($textContent[0] === ' ') { + $textContent = "\u{00A0}" . mb_substr($textContent, 1); + } + + if (mb_substr($textContent, -1, 1) === ' ') { + $textContent = mb_substr($textContent, 0, -1) . "\u{00A0}"; + } + + $element->textContent = $textContent; + } + } + } +}