From 19fdb871389635ac30f33817d6d558f3976eb9de Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 29 Aug 2020 14:05:58 +0200 Subject: [PATCH] Preserve the leading and trailing whitespace in `` on output Fixes #3536 --- .../output/node/HtmlOutputNodeKbd.class.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeKbd.class.php 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; + } + } + } +} -- 2.20.1