diff --git a/CHANGES.rst b/CHANGES.rst index 1d04e2987fe..e2f125998cc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/sphinx/roles.py b/sphinx/roles.py index cadfb5a027b..b4288fb488d 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -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]) @@ -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: diff --git a/tests/test_markup/test_markup.py b/tests/test_markup/test_markup.py index fb4df4c400b..75c992e2305 100644 --- a/tests/test_markup/test_markup.py +++ b/tests/test_markup/test_markup.py @@ -341,16 +341,20 @@ def get_verifier(verify, verify_re): ':kbd:`Control+X`', ( '

' + '' 'Control' - '+' + '+' 'X' + '' '

' ), ( '\\sphinxAtStartPar\n' + '\\sphinxkeyboard{\\sphinxupquote{' '\\sphinxkeyboard{\\sphinxupquote{Control}}' - '+' + '\\DUrole{kbd-sep}{+}' '\\sphinxkeyboard{\\sphinxupquote{X}}' + '}}' ), ), ( @@ -359,16 +363,20 @@ def get_verifier(verify, verify_re): ':kbd:`Alt+^`', ( '

' + '' 'Alt' - '+' + '+' '^' + '' '

' ), ( '\\sphinxAtStartPar\n' + '\\sphinxkeyboard{\\sphinxupquote{' '\\sphinxkeyboard{\\sphinxupquote{Alt}}' - '+' + '\\DUrole{kbd-sep}{+}' '\\sphinxkeyboard{\\sphinxupquote{\\textasciicircum{}}}' + '}}' ), ), ( @@ -377,24 +385,28 @@ def get_verifier(verify, verify_re): ':kbd:`M-x M-s`', ( '

' + '' 'M' - '-' + '-' 'x' - ' ' + ' ' 'M' - '-' + '-' 's' + '' '

' ), ( '\\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}}' + '}}' ), ), ( @@ -424,20 +436,24 @@ def get_verifier(verify, verify_re): ':kbd:`⌘+⇧+M`', ( '

' + '' '' - '+' + '+' '' - '+' + '+' 'M' + '' '

' ), ( '\\sphinxAtStartPar\n' + '\\sphinxkeyboard{\\sphinxupquote{' '\\sphinxkeyboard{\\sphinxupquote{⌘}}' - '+' + '\\DUrole{kbd-sep}{+}' '\\sphinxkeyboard{\\sphinxupquote{⇧}}' - '+' + '\\DUrole{kbd-sep}{+}' '\\sphinxkeyboard{\\sphinxupquote{M}}' + '}}' ), ), (