Skip to content

Some styles have bad contrasts #1718

@not-my-profile

Description

@not-my-profile

Currently some styles have bad contrasts, as seen in the official PIP documentation:

image

To make pygments more accessible, I think we should:

Original issue description

I wrote a small Python script to check how Pygments styles fare when judged according to the WCAG contrast standard.

The summary of my script is:

found 840 contrasts that fail to meet the WCAG AA standard
According to WCAG:
     AA contrast is >= 4.5
    AAA contrast is >= 7.0
    
=== Styles ranked by contrast ===
 avg   min  name
 3.4   2.5  solarized-light
 4.2   1.4  stata-dark
 4.3   2.8  solarized-dark
 5.5   1.3  paraiso-light
 6.2   1.3  paraiso-dark
 6.3   1.0  rrt
 7.0   1.0  inkpot
 7.3   1.7  friendly
 7.5   1.6  perldoc
 7.5   2.1  native
 7.6   1.8  emacs
 7.8   1.3  vim
 7.9   1.4  monokai
 8.0   1.4  manni
 8.7   3.1  lovelace
 8.7   1.8  default
 8.9   2.6  arduino
 9.2   1.9  autumn
 9.3   1.9  pastie
 9.6   1.0  rainbow_dash
 9.9   1.9  trac
10.1   1.4  murphy
10.4   1.0  tango
10.7   1.9  fruity
10.7   1.9  colorful
11.1   1.9  sas
13.0   2.5  abap
13.2   1.9  stata
13.2   1.9  stata-light
13.8   1.9  borland
13.9   5.1  xcode
14.4   3.6  igor
14.7   3.5  algol
14.7   3.5  algol_nu
15.7   3.6  vs
21.0  21.0  bw

My script also reports which rules don't meet the AA standard per style sorted by contrast, e.g. for the default style:

=== default ===
1.81 Token.Text.Whitespace
2.63 Token.Name.Label
2.68 Token.Name.Entity
3.28 Token.Generic.Inserted
3.34 Token.Generic.Output
3.34 Token.Comment.Preproc
3.36 Token.Name.Attribute
3.68 Token.Literal.String.Interpol
3.68 Token.Literal.String.Regex
3.76 Token.Generic.Error
3.93 Token.Literal.String.Escape
4.28 Token.Comment
4.28 Token.Comment.Hashbang
4.28 Token.Comment.Multiline
4.28 Token.Comment.PreprocFile
4.28 Token.Comment.Single
4.28 Token.Comment.Special
4.34 Token.Name.Exception

I am not saying that every Pygments style needs to have an AA contrast for every token type, but I think at least the default style should, since it's probably the most used one. If you want to I can send a PR to add my script into the scripts directory.

To improve the accessibility long term, I think it would make sense to incorporate the script into your CI pipeline with a given minimum contrast, making the pipeline fail if any style fails to meet this minimum. As the worst contrasts are improved this minimum contrast could then be gradually raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions