summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMatthäus G. Chajdas <Anteru@users.noreply.github.com>2021-11-21 16:51:26 +0100
committerGitHub <noreply@github.com>2021-11-21 16:51:26 +0100
commit32f845e6aafb6b4b59394a76396d4d7b6785e332 (patch)
treeb7a2936d92b6f4f3a8e378b697625f9b0420a419 /doc
parent4b7ce44b17dac1e042598a07ba0327076168e84f (diff)
parentc81dd6efb0495a780a63a1d409084fadf0367b94 (diff)
downloadpygments-git-32f845e6aafb6b4b59394a76396d4d7b6785e332.tar.gz
Merge pull request #1956 from not-my-profile/sort-style-gallery
Sort styles in gallery by background luminance
Diffstat (limited to 'doc')
-rw-r--r--doc/conf.py10
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):