diff options
author | Martin Fischer <martin@push-f.com> | 2021-12-23 07:58:20 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-23 07:58:20 +0100 |
commit | 4466c97f475f7913dd3f8a31bbe59c2028520927 (patch) | |
tree | d97819fc244b05f433caea1fc1eefca7cf5c5292 /pygments_wcag_check.py | |
parent | c629c3a0f01b7b5ccaacf7fb85df10ae5d59de9b (diff) |
add Makefile and format with black
Diffstat (limited to 'pygments_wcag_check.py')
-rwxr-xr-x | pygments_wcag_check.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/pygments_wcag_check.py b/pygments_wcag_check.py index 2a1e917..15993eb 100755 --- a/pygments_wcag_check.py +++ b/pygments_wcag_check.py @@ -6,6 +6,7 @@ import statistics import pygments.styles import wcag_contrast_ratio + def hex2rgb(hexstr): hexstr = hexstr.lstrip('#') r = int(hexstr[:2], 16) / 255 @@ -13,6 +14,7 @@ def hex2rgb(hexstr): b = int(hexstr[4:], 16) / 255 return (r, g, b) + total_wcag_fails = 0 styles = [] @@ -26,14 +28,19 @@ for name in pygments.styles.get_all_styles(): hex2rgb(style['color'] or '#000000') # we default to black because browsers also do ), - ttype - ) for ttype, style in style.list_styles() + ttype, + ) + for ttype, style in style.list_styles() ] if len(contrasts) == 0: continue styles.append( - (statistics.mean([x[0] for x in contrasts]), min([x[0] for x in contrasts]), name) + ( + statistics.mean([x[0] for x in contrasts]), + min([x[0] for x in contrasts]), + name, + ) ) bad_contrasts = [c for c in contrasts if not wcag_contrast_ratio.passes_AA(c[0])] @@ -50,10 +57,12 @@ for name in pygments.styles.get_all_styles(): if total_wcag_fails: print(f'found {total_wcag_fails} contrasts that fail to meet the WCAG AA standard') - print('''According to WCAG: + print( + '''According to WCAG: AA contrast is >= 4.5 AAA contrast is >= 7.0 - ''') + ''' + ) print('=== Styles ranked by contrast ===') print(' avg min name') for contrast, minimum, name in sorted(styles): |