Skip to content

Commit

Permalink
Merge pull request #8621 from tk0miya/8618_kbd_for_single_separator
Browse files Browse the repository at this point in the history
Fix #8618: html: incorrect HTML for single compound-kdb separators
  • Loading branch information
tk0miya committed Dec 31, 2020
2 parents a1d501d + 6a53c53 commit 332d80b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/html/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
18 changes: 18 additions & 0 deletions tests/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ def get(name):
'</kbd></p>'),
'\\sphinxkeyboard{\\sphinxupquote{Control+X}}',
),
(
# kbd role
'verify',
':kbd:`Alt+^`',
('<p><kbd class="kbd docutils literal notranslate">'
'<kbd class="kbd docutils literal notranslate">Alt</kbd>'
'+'
'<kbd class="kbd docutils literal notranslate">^</kbd>'
'</kbd></p>'),
'\\sphinxkeyboard{\\sphinxupquote{Alt+\\textasciicircum{}}}',
),
(
# kbd role
'verify',
Expand All @@ -266,6 +277,13 @@ def get(name):
'</kbd></p>'),
'\\sphinxkeyboard{\\sphinxupquote{M\\sphinxhyphen{}x M\\sphinxhyphen{}s}}',
),
(
# kbd role
'verify',
':kbd:`-`',
'<p><kbd class="kbd docutils literal notranslate">-</kbd></p>',
'\\sphinxkeyboard{\\sphinxupquote{\\sphinxhyphen{}}}',
),
(
# non-interpolation of dashes in option role
'verify_re',
Expand Down

0 comments on commit 332d80b

Please sign in to comment.