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

Make test_contrasts.py ignore token.Whitespace #1938

Merged
merged 1 commit into from Nov 2, 2021

Conversation

not-my-profile
Copy link
Contributor

@not-my-profile not-my-profile commented Nov 2, 2021

With the VisibleWhitespaceFilter Pygments can be configured to replace
whitespace characters like spaces, tabs and newlines with Unicode
characters like ·, » and ¶ respectively.

The min_contrast metric is meant to represent the readability of a
style. Increasing it should mean that the style becomes more readable.

This commit therefore excludes the token.Whitespace contrast from the
min_contrast calculation, since giving whitespace characters a high
contrast would make them so intrusive that they would actually hinder
the readability of the source code.

Screenshots for illustration

Current default style:

image

WCAG AA would look like (which IMO is clearly less readable):

image

With the VisibleWhitespaceFilter Pygments can be configured to replace
whitespace characters like spaces, tabs and newlines with Unicode
characters like ·, » and ¶ respectively.

The min_contrast metric is meant to represent the readability of a
style. Increasing it should mean that the style becomes more readable.

This commit therefore excludes the token.Whitespace contrast from the
min_contrast calculation, since giving whitespace characters a high
contrast would make them so intrusive that they would actually hinder
the readability of the source code.
@Anteru
Copy link
Collaborator

Anteru commented Nov 2, 2021

Good catch. Another good reason to be more precise about whitespace handling, but that is in @blu-base capable hands.

@not-my-profile
Copy link
Contributor Author

Thanks :) Though I don't quite get your comment on whitespace precision.

@blu-base
Copy link
Contributor

blu-base commented Nov 2, 2021

In many lexers whitespaces are detected as the Text token, not the Text.Whitespace token.
It seems this has historical reasons, since the Whitespace token has only been introduced in the later development.
For this reason, there are many lexers which cannot make use of the VisibleWhitespaceFilter, yet - since there are no Whitespace token declared, or only some.

I started to review most of them in order to fix that inhomogenity. Though i just scratched the surface (#1905)

@Anteru Anteru merged commit 4f676c7 into pygments:master Nov 2, 2021
@Anteru Anteru self-assigned this Nov 2, 2021
@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Nov 2, 2021
@Anteru Anteru added this to the 2.11.0 milestone Nov 2, 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

3 participants