From 6a53c53d538202bf58ae1d2f4922a8fd0b5290e8 Mon Sep 17 00:00:00 2001
From: Takeshi KOMIYA
Date: Wed, 30 Dec 2020 21:12:00 +0900
Subject: [PATCH] Fix #8618: html: incorrect HTML for single compound-kdb
separators
---
CHANGES | 2 ++
sphinx/builders/html/transforms.py | 2 +-
tests/test_markup.py | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/CHANGES b/CHANGES
index 3a9f527ad3d..c44051f3f89 100644
--- a/CHANGES
+++ b/CHANGES
@@ -30,6 +30,8 @@ Bugs fixed
* #8594: autodoc: empty __all__ attribute is ignored
* #8306: autosummary: mocked modules are documented as empty page when using
:recursive: option
+* #8618: html: kbd role produces incorrect HTML when compound-key separators (-,
+ + or ^) are used as keystrokes
* #8094: texinfo: image files on the different directory with document are not
copied
diff --git a/sphinx/builders/html/transforms.py b/sphinx/builders/html/transforms.py
index c91da57e993..311b1b7a032 100644
--- a/sphinx/builders/html/transforms.py
+++ b/sphinx/builders/html/transforms.py
@@ -37,7 +37,7 @@ class KeyboardTransform(SphinxPostTransform):
"""
default_priority = 400
builders = ('html',)
- pattern = re.compile(r'(-|\+|\^|\s+)')
+ pattern = re.compile(r'(?<=.)(-|\+|\^|\s+)(?=.)')
def run(self, **kwargs: Any) -> None:
matcher = NodeMatcher(nodes.literal, classes=["kbd"])
diff --git a/tests/test_markup.py b/tests/test_markup.py
index a2bcb2dc1fe..53298aeda91 100644
--- a/tests/test_markup.py
+++ b/tests/test_markup.py
@@ -251,6 +251,17 @@ def get(name):
'
'),
'\\sphinxkeyboard{\\sphinxupquote{Control+X}}',
),
+ (
+ # kbd role
+ 'verify',
+ ':kbd:`Alt+^`',
+ (''
+ 'Alt'
+ '+'
+ '^'
+ '
'),
+ '\\sphinxkeyboard{\\sphinxupquote{Alt+\\textasciicircum{}}}',
+ ),
(
# kbd role
'verify',
@@ -266,6 +277,13 @@ def get(name):
''),
'\\sphinxkeyboard{\\sphinxupquote{M\\sphinxhyphen{}x M\\sphinxhyphen{}s}}',
),
+ (
+ # kbd role
+ 'verify',
+ ':kbd:`-`',
+ '-
',
+ '\\sphinxkeyboard{\\sphinxupquote{\\sphinxhyphen{}}}',
+ ),
(
# non-interpolation of dashes in option role
'verify_re',