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

Prohibit contrast degradation for styles via test #1919

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

not-my-profile
Copy link
Contributor

First PR to address #1718.

Web accessibility is important. Unfortunately currently many pygments
styles have rules with poor contrasts. This commit introduces a test
case that fails if the minimum contrast of a style gets worse, e.g:

E  AssertionError: contrast degradation for style 'borland'
E    The following rules have a contrast lower than the required 2.9:
E
E    * 1.90 Token.Text.Whitespace
E    * 2.80 Token.Generic.Heading
E    * 2.30 Token.Generic.Subheading
E
E  assert not 1.9 < 2.9

This is accomplished by storing the current minimum contrasts in
./tests/contrast/min_contrasts.json.

When you improve a minimum contrast the test fails with:

E  AssertionError: congrats, you improved a contrast! please run ./scripts/update_contrasts.py
E  assert not 1.9 > 0.9

Running the script as instructed updates the JSON file, making the test pass.

New styles are required to meet the WCAG AA contrast minimum of 4.5.

@Anteru Anteru self-requested a review October 24, 2021 16:41
Copy link
Collaborator

@Anteru Anteru left a comment

Choose a reason for hiding this comment

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

Thanks, that looks good. I wonder if the WCAG package should be part of the developer dependencies, if look at tox we already pull in pytest and there's no reason why we can't pull in more dependencies there. There's no need to copy/paste it into this project and it's super error prone as well.

Web accessibility is important. Unfortunately currently many pygments
styles have rules with poor contrasts. This commit introduces a test
case that fails if the minimum contrast of a style gets worse, e.g:

E  AssertionError: contrast degradation for style 'borland'
E    The following rules have a contrast lower than the required 2.9:
E
E    * 1.90 Token.Text.Whitespace
E    * 2.80 Token.Generic.Heading
E    * 2.30 Token.Generic.Subheading
E
E  assert not 1.9 < 2.9

This is accomplished by storing the current minimum contrasts in
./tests/contrast/min_contrasts.json.

When you improve a minimum contrast the test fails with:

E  AssertionError: congrats, you improved a contrast! please run ./scripts/update_contrasts.py
E  assert not 1.9 > 0.9

Running the script as instructed updates the JSON file, making the test pass.

New styles are required to meet the WCAG AA contrast minimum of 4.5.

First commit to address pygments#1718.
@not-my-profile not-my-profile requested a review from Anteru October 27, 2021 02:47
@Anteru Anteru self-assigned this Nov 1, 2021
@Anteru Anteru merged commit 8cfc682 into pygments:master Nov 1, 2021
@Anteru
Copy link
Collaborator

Anteru commented Nov 1, 2021

Thanks a lot, merged!

@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Nov 1, 2021
@Anteru Anteru added this to the 2.11.0 milestone Nov 1, 2021
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Nov 13, 2021
@Mango0x45 Mango0x45 mentioned this pull request Nov 21, 2021
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.

None yet

2 participants