diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-14 19:11:39 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-14 19:17:32 +0100 |
commit | c81dd6efb0495a780a63a1d409084fadf0367b94 (patch) | |
tree | 0c21768680709e1e8db5b2d5eaada13ce9883c08 /doc/conf.py | |
parent | d37c02ba8545d23fa9457b0c05384d945374eb40 (diff) | |
download | pygments-git-c81dd6efb0495a780a63a1d409084fadf0367b94.tar.gz |
Sort styles in gallery by background luminance
Diffstat (limited to 'doc/conf.py')
-rw-r--r-- | doc/conf.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/doc/conf.py b/doc/conf.py index 00900d71..18cf4736 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -237,6 +237,7 @@ def pg_context(app, pagename, templatename, ctx, event_arg): ctx['styles_sub_aa'] = [] for style in pygments.styles.get_all_styles(): aa = min_contrasts[style] >= test_contrasts.WCAG_AA_CONTRAST + bg_r, bg_g, bg_b = test_contrasts.hex2rgb(pygments.styles.get_style_by_name(style).background_color) ctx['styles_aa' if aa else 'styles_sub_aa'].append( dict( name=style, @@ -245,8 +246,17 @@ def pg_context(app, pagename, templatename, ctx, event_arg): lexer, pygments.formatters.HtmlFormatter(noclasses=True, style=style), ), + # from https://en.wikipedia.org/wiki/Relative_luminance + bg_luminance=(0.2126*bg_r + 0.7152*bg_g + 0.0722*bg_b) ) ) + # sort styles according to their background luminance (light styles first) + # if styles have the same background luminance sort them by their name + # the default style is always displayed first + default_style = ctx['styles_aa'].pop(0) + ctx['styles_aa'].sort(key=lambda s: (-s['bg_luminance'], s['name'])) + ctx['styles_aa'].insert(0, default_style) + ctx['styles_sub_aa'].sort(key=lambda s: (-s['bg_luminance'], s['name'])) def setup(app): |