Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kbd role generates HTML that's difficult/impossible to style for compound-keystrokes #8619

Closed
johnnovak opened this issue Dec 30, 2020 · 2 comments
Labels
builder:html markup type:enhancement enhance or introduce a new feature
Milestone

Comments

@johnnovak
Copy link

Describe the bug

The :kbd: role doesn't mark container <kbd> elements with a CSS class, so they can be styled differently that child <kbd> elements representing actual keystrokes.

To Reproduce

For the below input

:kbd:`A`

:kbd:`Shift+X`

the following output is generated:

<kbd class="kbd docutils literal notranslate">A</kbd>

<kbd class="kbd docutils literal notranslate">
  <kbd class="kbd docutils literal notranslate">Shift</kbd>+
  <kbd class="kbd docutils literal notranslate">X</kbd>
</kbd>

Now we have a problem here: there is no way to differentiate between the parent container <kbd> element and the child <kbd> element with CSS selectors! If we provide a CSS style to draw a border around a <kbd> element, so single keystrokes are displayed correctly, then in the second example we'd get a double border (borders around the child elements, and another border around the parent element).

If you want to have borders around single keystrokes, and only around the child <kbd> elements in compound keystrokes, as shown on the screenshot below, the only way is to differentiate the container and child <kbd> elements with a CSS class.

image

Expected behavior

Single keystrokes are fine as they are, no change needed:

<kbd class="kbd docutils literal notranslate">A</kbd>

For compound keystrokes, the container <kbd> element should be marked with a CSS class (e.g. compound) so it can be styled differently than the child <kbd> elements:

<kbd class="kbd compound docutils literal notranslate">
  <kbd class="kbd docutils literal notranslate">Shift</kbd>+
  <kbd class="kbd docutils literal notranslate">X</kbd>
</kbd>

Environment info

  • OS: Windows
  • Python version: 3.9.1
  • Sphinx version: 3.4.0
  • Sphinx extensions: -
  • Extra tools: -
@idnsunset
Copy link

Quite agree, the outer <kbd> and inner <kbd> should be given different attributes for distinction. CSS has no way of selecting parent element so we are not able to determine whether a <kbd> element contains nested <kbd>.

With key combination and certain style for <kbd>, we get:

87524709-cb7c6300-c688-11ea-9640-9ee1cf217f58

@tk0miya tk0miya added type:enhancement enhance or introduce a new feature builder:html markup and removed type:bug labels Dec 30, 2020
@tk0miya tk0miya added this to the 3.5.0 milestone Dec 30, 2020
@tk0miya
Copy link
Member

tk0miya commented Dec 30, 2020

+1: Reasonable. Do you have a good naming for the <kbd> tag?

tk0miya added a commit that referenced this issue Dec 31, 2020
Close #8619: html: kbd role generates customizable HTML tags for compound keys
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
builder:html markup type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

3 participants