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

Rendering of :kbd: role is a bit off #322

Closed
ruslo opened this issue Feb 7, 2024 · 7 comments
Closed

Rendering of :kbd: role is a bit off #322

ruslo opened this issue Feb 7, 2024 · 7 comments

Comments

@ruslo
Copy link
Contributor

ruslo commented Feb 7, 2024

Here is how :kbd: rendered in a light theme:

Screenshot from 2024-02-07 16-51-13

It seems that the top of the object is missing.

It's slightly better with a dark theme:

Screenshot from 2024-02-07 16-51-23

Same code for the read-the-docs theme:

Screenshot from 2024-02-07 16-58-56

Live samples:

@2bndy5
Copy link
Collaborator

2bndy5 commented Feb 7, 2024

Can you supply the RST code to reproduce?

It looks like the undesired offset happens when there's nested <kbd> elements.

<kbd>
  <kbd>Ctrl</kbd>
  +
  <kbd>F</kbd>
</kbd>

Have you also looked into the keys role? The keys role's CSS is exclusive to this theme because the CSS is inherited from mkdocs-material theme...

@ruslo
Copy link
Contributor Author

ruslo commented Feb 8, 2024

Can you supply the RST code to reproduce?

See: highlight_text.rst

Have you also looked into the keys role?

Okay, it helped with the nested case 👍 But the top of the object is still not distinct:

Screenshot from 2024-02-08 17-34-03

Compare with:

Screenshot from 2024-02-07 16-58-56

@2bndy5
Copy link
Collaborator

2bndy5 commented Feb 8, 2024

CSS for the keys role is inherited from mkdocs-material source: src/assets/stylesheets/main/extensions/pymdownx/_keys.scss.

We also don't use any CSS from sphinx basic theme: sphinx/themes/basic/static/basic.css_t. But I don't see any CSS rules specific to kbd elements there.

Lastly, the RTD sphinx theme adds its own CSS specific to kbd elements: See their src/sass/_theme_rst.sass file.

So, to solve this we would need to add some CSS for kbd elements that are generated by the :kbd: role and be careful to not alter the rules defined for the :keys: role.

Just my opinion

I have some reservations about making any CSS changes because this theme is meant to be a port of the mkdocs-material theme to sphinx, not a material-design adaptation of the RTD sphinx theme... Looking at how the kbd elements are styled in upstream mkdocs-material, I feel like the current style is expected behavior.

There's also nothing stopping users from adding their own CSS to a project via sphinx, but having the different :keys: and :kbd: roles may complicate that idea too much for some doc authors.

@2bndy5
Copy link
Collaborator

2bndy5 commented Feb 8, 2024

There also seems to be slight differences in how different browsers render the kbd elements. In Firefox, the offset looks fine, but Chrome seems to position the kbd elements' contents a bit higher than Firefox.

@ruslo
Copy link
Contributor Author

ruslo commented Feb 8, 2024

I have some reservations about making any CSS changes because this theme is meant to be a port of the mkdocs-material theme to sphinx, not a material-design adaptation of the RTD sphinx theme... Looking at how the kbd elements are styled in upstream mkdocs-material, I feel like the current style is expected behavior

Okay, I see, indeed the issue is the same there.

In Firefox, the offset looks fine, but Chrome seems to position the kbd elements' contents a bit higher than Firefox

For me, Firefox looks similar:

Screenshot from 2024-02-08 18-40-26

@2bndy5
Copy link
Collaborator

2bndy5 commented Feb 8, 2024

I think the upstream artistic style can still be preserved while adding the requested visual distinction by simply darkening the kbd elements' background-color for light mode only:

[data-md-color-scheme="default"] kbd {
  background-color: #dfdfdf;
}

which results in
image

The background-color for kbd elements and the main body element is practically the same color in light mode.


EDIT: I also noticed that the pymdown.keys docs also override the background-color to use #ebebeb instead of the mkdocs-material's default #fafafa.

pymdown.keys mkdocs-material
image image

ruslo added a commit to ruslo/read_the_docs_template that referenced this issue Feb 8, 2024
@ruslo
Copy link
Contributor Author

ruslo commented Feb 8, 2024

I think the upstream artistic style can still be preserved while adding the requested visual distinction by simply darkening the kbd elements' background-color for light mode only

Look good:

Code: ruslo/read_the_docs_template@6951d7a

Thank you!

@ruslo ruslo closed this as completed Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants