Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Bugs fixed
* #13929: Duplicate equation label warnings now have a new warning
sub-type, ``ref.equation``.
Patch by Jared Dillard.
* #13876: Restore the ``compound`` class for groups of nodes generated
by the :rst:role:`kbd` role, and add the ``kbd-sep`` class to separators
within the group.
Patch by Brecht Machiels.


Testing
Expand Down
7 changes: 4 additions & 3 deletions sphinx/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ def run(self) -> tuple[list[Node], list[system_message]]:
if len(parts) == 1 or self._is_multi_word_key(parts):
return [nodes.literal(self.rawtext, self.text, classes=classes)], []

compound: list[Node] = []
compound = nodes.literal(self.rawtext, classes=classes)
compound['classes'].append('compound')
while parts:
if self._is_multi_word_key(parts):
key = ''.join(parts[:3])
Expand All @@ -509,9 +510,9 @@ def run(self) -> tuple[list[Node], list[system_message]]:
except IndexError:
break
else:
compound.append(nodes.Text(sep))
compound.append(nodes.inline(sep, sep, classes=['kbd-sep']))

return compound, []
return [compound], []

@staticmethod
def _is_multi_word_key(parts: list[str]) -> bool:
Expand Down
44 changes: 30 additions & 14 deletions tests/test_markup/test_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,20 @@ def get_verifier(verify, verify_re):
':kbd:`Control+X`',
(
'<p>'
'<kbd class="kbd compound docutils literal notranslate">'
'<kbd class="kbd docutils literal notranslate">Control</kbd>'
'+'
'<span class="kbd-sep">+</span>'
'<kbd class="kbd docutils literal notranslate">X</kbd>'
'</kbd>'
'</p>'
),
(
'\\sphinxAtStartPar\n'
'\\sphinxkeyboard{\\sphinxupquote{'
'\\sphinxkeyboard{\\sphinxupquote{Control}}'
'+'
'\\DUrole{kbd-sep}{+}'
'\\sphinxkeyboard{\\sphinxupquote{X}}'
'}}'
),
),
(
Expand All @@ -359,16 +363,20 @@ def get_verifier(verify, verify_re):
':kbd:`Alt+^`',
(
'<p>'
'<kbd class="kbd compound docutils literal notranslate">'
'<kbd class="kbd docutils literal notranslate">Alt</kbd>'
'+'
'<span class="kbd-sep">+</span>'
'<kbd class="kbd docutils literal notranslate">^</kbd>'
'</kbd>'
'</p>'
),
(
'\\sphinxAtStartPar\n'
'\\sphinxkeyboard{\\sphinxupquote{'
'\\sphinxkeyboard{\\sphinxupquote{Alt}}'
'+'
'\\DUrole{kbd-sep}{+}'
'\\sphinxkeyboard{\\sphinxupquote{\\textasciicircum{}}}'
'}}'
),
),
(
Expand All @@ -377,24 +385,28 @@ def get_verifier(verify, verify_re):
':kbd:`M-x M-s`',
(
'<p>'
'<kbd class="kbd compound docutils literal notranslate">'
'<kbd class="kbd docutils literal notranslate">M</kbd>'
'-'
'<span class="kbd-sep">-</span>'
'<kbd class="kbd docutils literal notranslate">x</kbd>'
' '
'<span class="kbd-sep"> </span>'
'<kbd class="kbd docutils literal notranslate">M</kbd>'
'-'
'<span class="kbd-sep">-</span>'
'<kbd class="kbd docutils literal notranslate">s</kbd>'
'</kbd>'
'</p>'
),
(
'\\sphinxAtStartPar\n'
'\\sphinxkeyboard{\\sphinxupquote{'
'\\sphinxkeyboard{\\sphinxupquote{M}}'
'\\sphinxhyphen{}'
'\\DUrole{kbd-sep}{\\sphinxhyphen{}}'
'\\sphinxkeyboard{\\sphinxupquote{x}}'
' '
'\\DUrole{kbd-sep}{ }'
'\\sphinxkeyboard{\\sphinxupquote{M}}'
'\\sphinxhyphen{}'
'\\DUrole{kbd-sep}{\\sphinxhyphen{}}'
'\\sphinxkeyboard{\\sphinxupquote{s}}'
'}}'
),
),
(
Expand Down Expand Up @@ -424,20 +436,24 @@ def get_verifier(verify, verify_re):
':kbd:`⌘+⇧+M`',
(
'<p>'
'<kbd class="kbd compound docutils literal notranslate">'
'<kbd class="kbd docutils literal notranslate">⌘</kbd>'
'+'
'<span class="kbd-sep">+</span>'
'<kbd class="kbd docutils literal notranslate">⇧</kbd>'
'+'
'<span class="kbd-sep">+</span>'
'<kbd class="kbd docutils literal notranslate">M</kbd>'
'</kbd>'
'</p>'
),
(
'\\sphinxAtStartPar\n'
'\\sphinxkeyboard{\\sphinxupquote{'
'\\sphinxkeyboard{\\sphinxupquote{⌘}}'
'+'
'\\DUrole{kbd-sep}{+}'
'\\sphinxkeyboard{\\sphinxupquote{⇧}}'
'+'
'\\DUrole{kbd-sep}{+}'
'\\sphinxkeyboard{\\sphinxupquote{M}}'
'}}'
),
),
(
Expand Down
Loading