Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Accessibility - Fix code syntax highlighting errors (light mode) - #34376

Merged
betatim merged 11 commits into
scikit-learn:mainfrom
DeaMariaLeon:accessi1
Jun 26, 2026
Merged

Accessibility - Fix code syntax highlighting errors (light mode)#34376
betatim merged 11 commits into
scikit-learn:mainfrom
DeaMariaLeon:accessi1

Conversation

@DeaMariaLeon

@DeaMariaLeon DeaMariaLeon commented Jun 23, 2026

Copy link
Copy Markdown
Member

Reference Issues/PRs

Towards #34366

What does this implement/fix? Explain your changes.

  1. Changing the colors of the code syntax highlighting.
    2. Try to eliminate an error generated from a table's empty table head.

Point 1:
We get the colors from pygments and set them in conf.py :

"pygments_light_style": "tango",
"pygments_dark_style": "monokai"

But pygments documentation shows the "tango" style under section Styles with a lower contrast :
"The following styles do not meet the WCAG 2.1 AA contrast minimum, so they might be difficult to read for people with suboptimal vision. If you want your highlighted code to be well readable for other people, you should use one of the earlier styles instead."

First time contributor introduction

AI usage disclosure

I used AI assistance for:

Any other comments?

First part of the fix - I want to build the documentation to check if some of the accessibility errors go away in WAVE page.

@betatim

betatim commented Jun 24, 2026

Copy link
Copy Markdown
Member

Looking forward to seeing this!

When you are ready for reviews can you include some screenshots of the before and after look? I think that helps a lot to make it clear what the change looks like and what it should look like. That way if I see something that looks different to the screenshot it is clear that it isn't on purpose.

@DeaMariaLeon

DeaMariaLeon commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

120 contrast errors testing the Column Transformer with Mixed Types example in WAVE (stable version)

Screenshot 2026-06-24 at 15 30 10

With this PR, 0 contrast errors (please note that I'm testing just one example, not the whole website):
Screenshot 2026-06-24 at 15 56 46

Code syntax highlighting before this PR

Screenshot 2026-06-24 at 15 31 43 Screenshot 2026-06-24 at 15 31 58

Code syntax highlighting after this PR

Screenshot 2026-06-24 at 15 51 13 Screenshot 2026-06-24 at 15 51 46

The remaining error is the empty table header which is a pandas issue. I tried several things and kept getting WAVE errors. Solving it is important: a user with a screen reader loses orientation in the table (with this error).

I tried:

  1. naming the index - With Sphinx I get an extra empty row and there are even more errors.
  2. reseting the index - a new index gets generated and still an error.
  3. Hiding the index is another option - that may not be desirable (?)
    In the 3 cases those commands will be visible on the example and the user may not understand the reason for it.
Screen shot of the table when naming the index: Screenshot 2026-06-24 at 16 10 54

The 258 warnings are related to actions available only with the mouse.

@DeaMariaLeon DeaMariaLeon changed the title DOC Fix some accessibility issues DOC Fix code syntax highlighting accessibility errors Jun 24, 2026
@DeaMariaLeon
DeaMariaLeon marked this pull request as ready for review June 24, 2026 15:22
@betatim

betatim commented Jun 25, 2026

Copy link
Copy Markdown
Member

I like the new look!

One thing that I am wondering about: in the old style light and dark mode as well as in the new style dark mode the output of a cell has a slightly different background colour (background of "R2 score with ability")

Screenshot 2026-06-25 at 11 22 13

With the new style and light mode it looks like this:

Screenshot 2026-06-25 at 11 24 25

What do people think of this? At first it was weird/felt like something was missing, but after looking at a few pages I stopped noticing it. I think if anything we should be consistent across dark and light mode. But I think I am fine with either option (no background colour or with background colour).

Comment thread doc/scss/custom.scss
@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Regarding #34376 (comment),
The Pygments white backgrounds are the ones that pass the WAVE test: https://pygments.org/styles/#:~:text=Styles%20with%20a%20lower%20contrast for accessibility.
(The "default" one didn't pass it).

@betatim

betatim commented Jun 25, 2026

Copy link
Copy Markdown
Member

Is there more work you want to do or should we ask for people's opinions/reviews?

Comment thread doc/scss/custom.scss

@betatim betatim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me!

@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Is there more work you want to do?

No, thanks again.

@AnneBeyer

Copy link
Copy Markdown
Contributor

Thanks, @DeaMariaLeon, that is a useful small change!
Does WAVE automatically also check the dark theme (the screenshots you posted are all on light)? monokai is listed among the recommended styles, but since you also had to overwrite a setting in the light theme, it might be useful to check that for dark mode as well?

On the linter failure: You just have to merge main, then it should be green again.

@DeaMariaLeon

DeaMariaLeon commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

Does WAVE automatically also check the dark theme

No, that is a known limitation.

On the linter failure: You just have to merge main, then it should be green again.

I know. But I thought what's the point if it's going to be merged with main anyway.

that is a useful small change

I don't think that trying to help people with disabilities or visual impairments is a small change.
But there is more work to do.

@AnneBeyer

Copy link
Copy Markdown
Contributor

Does WAVE automatically also check the dark theme

No, that is a known limitation.

But have you checked manually (by switching to dark mode in your browser)?

But I thought what's the point if it's going to be merged with main anyway.

I didn't know a PR can be merged if a test is failing. Sorry for pointing it out then.

I don't think that trying to help people with disabilities or visual impairments is a small change.

I was referring to the small change in code that you found that already made many warnings disappear. I don't understand how you read that into my comment.

@DeaMariaLeon

Copy link
Copy Markdown
Member Author

Does WAVE automatically also check the dark theme

No, that is a known limitation.

But have you checked manually (by switching to dark mode in your browser)?

Yes, of course. When I set the dark mode on my browser, the report always comes back "light mode".
In their documentation they recommend installing their extension if one needs to check dynamic websites. I avoided installing it because of all my personal data that the tool is able to get.

I also forced the browser dark with the devtools - not only with the icon on the page, but I got the same result from WAVE. So testing dark was not available. There are more tools to test these things, or we can force a page that only has the dark mode (totally eliminating the light mode)... but this needs more investigation/work.

I guess the ultimate and best test would be asking someone who actually has visual issues, or at least use a screen reader in dark mode.


I didn't know a PR can be merged if a test is failing. Sorry for pointing it out then.

Nothing to be sorry about. Maybe it's more safe to do the merge myself like you said. Thanks.


I was referring to the small change in code that you found that already made many warnings disappear. I don't understand how you read that into my comment.

Everybody can get better at communicating. Often, phrases can be interpreted in different ways, that's normal.
But now I have to explain why I read it the way I read it. :-D


To be clear: the warnings were not removed, we still have them and need to be fixed. It needs investigation, but it's not that easy.
What this PR should remove are the errors of contrast whenever there is code in the whole website, even if I only tested one page. (in light mode, like you said).

@AnneBeyer AnneBeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is an improvement as is, so LGTM.

@betatim

betatim commented Jun 26, 2026

Copy link
Copy Markdown
Member

Let's merge this! It is an improvement to what we have right now. Maybe if we figure out a way to run the audit with dark mode we can make another PR to work on those findings.

@betatim
betatim merged commit bf2dfd4 into scikit-learn:main Jun 26, 2026
38 checks passed
@DeaMariaLeon
DeaMariaLeon deleted the accessi1 branch June 26, 2026 15:54
@DeaMariaLeon DeaMariaLeon moved this to Done in Labs Jun 27, 2026
@DeaMariaLeon DeaMariaLeon changed the title DOC Fix code syntax highlighting accessibility errors Accessibility - Fix code syntax highlighting accessibility errors Jun 27, 2026
@DeaMariaLeon DeaMariaLeon changed the title Accessibility - Fix code syntax highlighting accessibility errors Accessibility - Fix code syntax highlighting errors Jun 27, 2026
@DeaMariaLeon DeaMariaLeon changed the title Accessibility - Fix code syntax highlighting errors Accessibility - Fix code syntax highlighting errors (light mode) Jul 7, 2026
@DeaMariaLeon

Copy link
Copy Markdown
Member Author

It turns out that contrast checks can be done with Firefox, including dark mode.
Moreover, it finds more issues than the WAVE tool (and most other automatic tools, apparently).

From their docs:
"WAVE cannot detect all contrast issues. It does not account for background images, gradients, transparency, etc. It also cannot detect text that is part of an image. A manual scan for these types of contrast issues is still necessary."

So, we still have contrast issues in light mode (on the landing page, logo, etc. -- not in the code highlighting. 🥳).

Dark mode's needs fixing as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants