Skip to content

Use consistent line-height for light & dark theme #227

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

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Apr 8, 2025

While working on the copy button, I noticed the line height of the pre element differs for the light and dark theme. It is set to 120% for the light theme 125% for the dark theme, which is not a huge difference but it's better to be consistent.

The reason for the discrepancy is the order in which the css is included in the <head>. For the light theme, classic.css takes precedence:
Screenshot from 2025-04-08 22-31-31

Whereas for the dark theme, it is pygments_dark.css which is the last stylesheet in the <head>:
Screenshot from 2025-04-08 22-31-41

This seems to be related to how sphinx inserts the css for pygments:
https://github.com/sphinx-doc/sphinx/blob/a6d7ae16739bf92a032a7c4df0297db7cf120ec9/sphinx/builders/html/__init__.py#L258-L262

In any case, we can fix this by simply setting the line height in pydoctheme.css.


📚 Documentation preview 📚: https://python-docs-theme-previews--227.org.readthedocs.build/

@@ -328,6 +328,10 @@ tt, code, pre {
font-size: 96.5%;
}

pre {
line-height: 125%;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the initial value for the theme, rather than the overridden one:

Suggested change
line-height: 125%;
line-height: 120%;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check later if this will work or if we need a more specific selector since pygments_dark.css is included last and sets 125%

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was indeed the case. I went for div.body pre to increase the specificity and override pygments_dark.css

@AA-Turner AA-Turner merged commit 06987c2 into python:main Apr 10, 2025
14 checks passed
@tomasr8 tomasr8 deleted the line-height branch April 10, 2025 19:22
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

Successfully merging this pull request may close these issues.

2 participants