Last active
June 3, 2022 02:55
-
-
Save asmeurer/d78409ea033aeeb764a11bb4acaeccc2 to your computer and use it in GitHub Desktop.
WGAC AA pygments styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Making WCAG AA compliant pygments themes with better color contrast | |
The WCAG AA standard requires colors to have at least 4.5 contrast ratio | |
against their background. Most pygments styles do not follow this, but with | |
some (usually small) modifications, they can. | |
This process is a little hacky, but it works. It would be better to convert | |
this whole process into a single Python script/library, but I got the themes I | |
care about. If anyone else wants to do that, please do so. Here are the steps | |
I used | |
1. Clone this repo | |
https://github.com/mpchadwick/pygments-high-contrast-stylesheets. This repo | |
already has some pre-build AA complaint CSS files for a few pygments | |
themes. However, not every theme is there, and also it's just the CSS, not | |
the full pygments theme. | |
2. Take the theme you want, say the theme is `'native'`, and use pygments to | |
export the CSS for the theme to `native.css` (the filename matters). | |
```py | |
theme_name = 'native' | |
import pygments | |
with open(theme_name + '.css', 'w') as f: | |
pygments.formatters.HtmlFormatter(style=pygments.styles.get_style_by_name(theme_name)).get_style_defs('.highlight') | |
``` | |
3. `cd` into the `tools` directory of the `pygments-high-contrast-stylesheets` | |
repo and run `bundle install` (you will need Ruby for this to work). | |
4. Run | |
``` | |
./make-stylesheet path/to/this/gist/<style>.css path/to/this/gist/<style>-hc.css > path/to/this/gist/<style>-output | |
``` | |
Replace `path/to/this/gist` with the path to this gist, and replace | |
`<style>` with the name of the pygments style (e.g., `native`). Note that | |
the filename `<style-name>-output` is important. | |
5. `cd` back to this gist and run | |
``` | |
python fixed_style.py <style-name> | |
``` | |
This will print out a dictionary of updated style definitions. | |
6. Create the style with something like | |
```py | |
from pygments.styles.native import NativeStyle | |
from pygments.token import Comment, Generic, Literal, Name, Number, Text | |
class NativeHighContrastStyle(NativeStyle): | |
""" | |
Like native, but with higher contrast colors. | |
""" | |
styles = NativeStyle.styles | |
# These are adjusted to have better color contrast against the background | |
styles.update({ | |
Comment.Preproc: 'bold #e15a5a', | |
Comment.Special: 'bold #f75050 bg:#520000', | |
Generic.Deleted: '#e75959', | |
Generic.Error: '#e75959', | |
Generic.Traceback: '#e75959', | |
Literal.Number: '#438dc4', | |
Name.Builtin: '#2594a1', | |
# We also remove the underline here from the original style | |
Name.Class: '#548bd3', | |
Name.Function: '#548bd3', | |
# We also remove the underline here from the original style | |
Name.Namespace: '#548bd3', | |
Text.Whitespace: '#878787', | |
Literal.Number.Bin: '#438dc4', | |
Literal.Number.Float: '#438dc4', | |
Literal.Number.Hex: '#438dc4', | |
Literal.Number.Integer: '#438dc4', | |
Literal.Number.Oct: '#438dc4', | |
Name.Builtin.Pseudo: '#2594a1', | |
Name.Function.Magic: '#548bd3', | |
Literal.Number.Integer.Long: '#438dc4', | |
}) | |
``` | |
Replace `native` with the style you are updating and the dictionary with | |
the dictionary printed by the above script. See `scripts.py` for an example | |
that also includes the `sphinx` style. You can also make additional | |
modifications here if you like (e.g., I removed the underlining of module | |
names in `native` because I don't like it), but if you update colors be | |
sure they are have at least 4.5 contrast ratio. | |
7. You won't need the `<style>.css`, `<style>-output` or `<style>-hc.css` | |
files any more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
OUTPUT_LINE_RE = re.compile(r"Fixed: \.highlight \.(.*) \| Original Ratio: .* \| Original Color: (.*) \| Background: .* \| New Color: (.*)") | |
CSS_COMMENT = re.compile("/\* (.*) \*/") | |
BACKGROUND_COLOR = re.compile("background-color: (\S*)") | |
FONT_STYLE = re.compile("(?:font-style|font-weight|text-decoration): ([a-z]*)") | |
def main(): | |
style = sys.argv[1] | |
with open(f"{style}-output") as f: | |
output_lines = f.readlines() | |
with open(f"{style}.css") as f: | |
css_lines = f.readlines() | |
styles_dict = {} | |
for output_line in output_lines: | |
m = OUTPUT_LINE_RE.match(output_line) | |
if not m: | |
print("ERROR: Could not match line:", output_line) | |
continue | |
selector, original, new = m.groups() | |
color = "#" + new | |
for css_line in css_lines: | |
if (css_line.startswith("." + selector) or | |
css_line.startswith('.highlight .' + selector)): | |
m2 = CSS_COMMENT.search(css_line) | |
if not m2: | |
print("ERROR: Could not match comment in CSS line:", css_line) | |
continue | |
pygments_class = m2.group(1) | |
if (m3 := BACKGROUND_COLOR.search(css_line)): | |
color += f" bg:{m3.group(1)}" | |
if (m3 := FONT_STYLE.search(css_line)): | |
color = m3.group(1) + " " + color | |
break | |
else: | |
print("ERROR: Could not find CSS line for selector:", selector) | |
continue | |
styles_dict[pygments_class] = color | |
print("{") | |
for style, color in styles_dict.items(): | |
print(f" {style}: {color!r},") | |
print("}") | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) 2022 Aaron Meurer | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixed: .highlight .cp | Original Ratio: 3.0491540565983817 | Original Color: cd2828 | Background: 202020 | New Color: e15a5a | |
Fixed: .highlight .cs | Original Ratio: 3.216033461119466 | Original Color: e50808 | Background: 202020 | New Color: f75050 | |
Fixed: .highlight .gd | Original Ratio: 3.107364441355437 | Original Color: d22323 | Background: 202020 | New Color: e75959 | |
Fixed: .highlight .gr | Original Ratio: 3.107364441355437 | Original Color: d22323 | Background: 202020 | New Color: e75959 | |
Fixed: .highlight .gt | Original Ratio: 3.107364441355437 | Original Color: d22323 | Background: 202020 | New Color: e75959 | |
Fixed: .highlight .m | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .nb | Original Ratio: 4.306991238898793 | Original Color: 24909d | Background: 202020 | New Color: 2594a1 | |
Fixed: .highlight .nc | Original Ratio: 4.020970786041158 | Original Color: 447fcf | Background: 202020 | New Color: 548bd3 | |
Fixed: .highlight .nf | Original Ratio: 4.020970786041158 | Original Color: 447fcf | Background: 202020 | New Color: 548bd3 | |
Fixed: .highlight .nn | Original Ratio: 4.020970786041158 | Original Color: 447fcf | Background: 202020 | New Color: 548bd3 | |
Fixed: .highlight .w | Original Ratio: 2.8376383429263035 | Original Color: 666666 | Background: 202020 | New Color: 878787 | |
Fixed: .highlight .mb | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .mf | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .mh | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .mi | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .mo | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 | |
Fixed: .highlight .bp | Original Ratio: 4.306991238898793 | Original Color: 24909d | Background: 202020 | New Color: 2594a1 | |
Fixed: .highlight .fm | Original Ratio: 4.020970786041158 | Original Color: 447fcf | Background: 202020 | New Color: 548bd3 | |
Fixed: .highlight .il | Original Ratio: 3.389384131855589 | Original Color: 3677a9 | Background: 202020 | New Color: 438dc4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.highlight .hll { background-color: #404040 } | |
.highlight { background: #202020; color: #d0d0d0 } | |
.highlight .c { color: #999999; font-style: italic } /* Comment */ | |
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ | |
.highlight .esc { color: #d0d0d0 } /* Escape */ | |
.highlight .g { color: #d0d0d0 } /* Generic */ | |
.highlight .k { color: #6ab825; font-weight: bold } /* Keyword */ | |
.highlight .l { color: #d0d0d0 } /* Literal */ | |
.highlight .n { color: #d0d0d0 } /* Name */ | |
.highlight .o { color: #d0d0d0 } /* Operator */ | |
.highlight .x { color: #d0d0d0 } /* Other */ | |
.highlight .p { color: #d0d0d0 } /* Punctuation */ | |
.highlight .ch { color: #999999; font-style: italic } /* Comment.Hashbang */ | |
.highlight .cm { color: #999999; font-style: italic } /* Comment.Multiline */ | |
.highlight .cp { color: #cd2828; font-weight: bold } /* Comment.Preproc */ | |
.highlight .cpf { color: #999999; font-style: italic } /* Comment.PreprocFile */ | |
.highlight .c1 { color: #999999; font-style: italic } /* Comment.Single */ | |
.highlight .cs { color: #e50808; font-weight: bold; background-color: #520000 } /* Comment.Special */ | |
.highlight .gd { color: #d22323 } /* Generic.Deleted */ | |
.highlight .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */ | |
.highlight .gr { color: #d22323 } /* Generic.Error */ | |
.highlight .gh { color: #ffffff; font-weight: bold } /* Generic.Heading */ | |
.highlight .gi { color: #589819 } /* Generic.Inserted */ | |
.highlight .go { color: #cccccc } /* Generic.Output */ | |
.highlight .gp { color: #aaaaaa } /* Generic.Prompt */ | |
.highlight .gs { color: #d0d0d0; font-weight: bold } /* Generic.Strong */ | |
.highlight .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */ | |
.highlight .gt { color: #d22323 } /* Generic.Traceback */ | |
.highlight .kc { color: #6ab825; font-weight: bold } /* Keyword.Constant */ | |
.highlight .kd { color: #6ab825; font-weight: bold } /* Keyword.Declaration */ | |
.highlight .kn { color: #6ab825; font-weight: bold } /* Keyword.Namespace */ | |
.highlight .kp { color: #6ab825 } /* Keyword.Pseudo */ | |
.highlight .kr { color: #6ab825; font-weight: bold } /* Keyword.Reserved */ | |
.highlight .kt { color: #6ab825; font-weight: bold } /* Keyword.Type */ | |
.highlight .ld { color: #d0d0d0 } /* Literal.Date */ | |
.highlight .m { color: #3677a9 } /* Literal.Number */ | |
.highlight .s { color: #ed9d13 } /* Literal.String */ | |
.highlight .na { color: #bbbbbb } /* Name.Attribute */ | |
.highlight .nb { color: #24909d } /* Name.Builtin */ | |
.highlight .nc { color: #447fcf; text-decoration: underline } /* Name.Class */ | |
.highlight .no { color: #40ffff } /* Name.Constant */ | |
.highlight .nd { color: #ffa500 } /* Name.Decorator */ | |
.highlight .ni { color: #d0d0d0 } /* Name.Entity */ | |
.highlight .ne { color: #bbbbbb } /* Name.Exception */ | |
.highlight .nf { color: #447fcf } /* Name.Function */ | |
.highlight .nl { color: #d0d0d0 } /* Name.Label */ | |
.highlight .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */ | |
.highlight .nx { color: #d0d0d0 } /* Name.Other */ | |
.highlight .py { color: #d0d0d0 } /* Name.Property */ | |
.highlight .nt { color: #6ab825; font-weight: bold } /* Name.Tag */ | |
.highlight .nv { color: #40ffff } /* Name.Variable */ | |
.highlight .ow { color: #6ab825; font-weight: bold } /* Operator.Word */ | |
.highlight .w { color: #666666 } /* Text.Whitespace */ | |
.highlight .mb { color: #3677a9 } /* Literal.Number.Bin */ | |
.highlight .mf { color: #3677a9 } /* Literal.Number.Float */ | |
.highlight .mh { color: #3677a9 } /* Literal.Number.Hex */ | |
.highlight .mi { color: #3677a9 } /* Literal.Number.Integer */ | |
.highlight .mo { color: #3677a9 } /* Literal.Number.Oct */ | |
.highlight .sa { color: #ed9d13 } /* Literal.String.Affix */ | |
.highlight .sb { color: #ed9d13 } /* Literal.String.Backtick */ | |
.highlight .sc { color: #ed9d13 } /* Literal.String.Char */ | |
.highlight .dl { color: #ed9d13 } /* Literal.String.Delimiter */ | |
.highlight .sd { color: #ed9d13 } /* Literal.String.Doc */ | |
.highlight .s2 { color: #ed9d13 } /* Literal.String.Double */ | |
.highlight .se { color: #ed9d13 } /* Literal.String.Escape */ | |
.highlight .sh { color: #ed9d13 } /* Literal.String.Heredoc */ | |
.highlight .si { color: #ed9d13 } /* Literal.String.Interpol */ | |
.highlight .sx { color: #ffa500 } /* Literal.String.Other */ | |
.highlight .sr { color: #ed9d13 } /* Literal.String.Regex */ | |
.highlight .s1 { color: #ed9d13 } /* Literal.String.Single */ | |
.highlight .ss { color: #ed9d13 } /* Literal.String.Symbol */ | |
.highlight .bp { color: #24909d } /* Name.Builtin.Pseudo */ | |
.highlight .fm { color: #447fcf } /* Name.Function.Magic */ | |
.highlight .vc { color: #40ffff } /* Name.Variable.Class */ | |
.highlight .vg { color: #40ffff } /* Name.Variable.Global */ | |
.highlight .vi { color: #40ffff } /* Name.Variable.Instance */ | |
.highlight .vm { color: #40ffff } /* Name.Variable.Magic */ | |
.highlight .il { color: #3677a9 } /* Literal.Number.Integer.Long */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.highlight .hll { background-color: #ffffcc; } | |
.highlight { background: #eeffcc; } | |
.highlight .c { font-style: italic; color: #3c7a88; } | |
.highlight .err { border: 1px solid #FF0000; } | |
.highlight .k { color: #007020; font-weight: bold; } | |
.highlight .o { color: #666666; } | |
.highlight .ch { font-style: italic; color: #3c7a88; } | |
.highlight .cm { font-style: italic; color: #3c7a88; } | |
.highlight .cp { color: #007020; } | |
.highlight .cpf { font-style: italic; color: #3c7a88; } | |
.highlight .c1 { font-style: italic; color: #3c7a88; } | |
.highlight .cs { background-color: #fff0f0; color: #3a7784; } | |
.highlight .gd { color: #A00000; } | |
.highlight .ge { font-style: italic; } | |
.highlight .gr { color: #e60000; } | |
.highlight .gh { color: #000080; font-weight: bold; } | |
.highlight .gi { color: #008200; } | |
.highlight .go { color: #333333; } | |
.highlight .gp { font-weight: bold; color: #b75709; } | |
.highlight .gs { font-weight: bold; } | |
.highlight .gu { color: #800080; font-weight: bold; } | |
.highlight .gt { color: #0044DD; } | |
.highlight .kc { color: #007020; font-weight: bold; } | |
.highlight .kd { color: #007020; font-weight: bold; } | |
.highlight .kn { color: #007020; font-weight: bold; } | |
.highlight .kp { color: #007020; } | |
.highlight .kr { color: #007020; font-weight: bold; } | |
.highlight .kt { color: #902000; } | |
.highlight .m { color: #208050; } | |
.highlight .s { color: #4070a0; } | |
.highlight .na { color: #4070a0; } | |
.highlight .nb { color: #007020; } | |
.highlight .nc { font-weight: bold; color: #0e7ba6; } | |
.highlight .no { color: #2b79a1; } | |
.highlight .nd { color: #555555; font-weight: bold; } | |
.highlight .ni { font-weight: bold; color: #c54629; } | |
.highlight .ne { color: #007020; } | |
.highlight .nf { color: #06287e; } | |
.highlight .nl { color: #002070; font-weight: bold; } | |
.highlight .nn { font-weight: bold; color: #0e7ba6; } | |
.highlight .nt { color: #062873; font-weight: bold; } | |
.highlight .nv { color: #ab40cd; } | |
.highlight .ow { color: #007020; font-weight: bold; } | |
.highlight .w { color: #707070; } | |
.highlight .mb { color: #208050; } | |
.highlight .mf { color: #208050; } | |
.highlight .mh { color: #208050; } | |
.highlight .mi { color: #208050; } | |
.highlight .mo { color: #208050; } | |
.highlight .sa { color: #4070a0; } | |
.highlight .sb { color: #4070a0; } | |
.highlight .sc { color: #4070a0; } | |
.highlight .dl { color: #4070a0; } | |
.highlight .sd { color: #4070a0; font-style: italic; } | |
.highlight .s2 { color: #4070a0; } | |
.highlight .se { color: #4070a0; font-weight: bold; } | |
.highlight .sh { color: #4070a0; } | |
.highlight .si { font-style: italic; color: #3973b7; } | |
.highlight .sx { color: #b75709; } | |
.highlight .sr { color: #235388; } | |
.highlight .s1 { color: #4070a0; } | |
.highlight .ss { color: #517918; } | |
.highlight .bp { color: #007020; } | |
.highlight .fm { color: #06287e; } | |
.highlight .vc { color: #ab40cd; } | |
.highlight .vg { color: #ab40cd; } | |
.highlight .vi { color: #ab40cd; } | |
.highlight .vm { color: #ab40cd; } | |
.highlight .il { color: #208050; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixed: .highlight .c | Original Ratio: 4.207671142780154 | Original Color: 408090 | Background: eeffcc | New Color: 3c7a88 | |
Fixed: .highlight .ch | Original Ratio: 4.207671142780154 | Original Color: 408090 | Background: eeffcc | New Color: 3c7a88 | |
Fixed: .highlight .cm | Original Ratio: 4.207671142780154 | Original Color: 408090 | Background: eeffcc | New Color: 3c7a88 | |
Fixed: .highlight .cpf | Original Ratio: 4.207671142780154 | Original Color: 408090 | Background: eeffcc | New Color: 3c7a88 | |
Fixed: .highlight .c1 | Original Ratio: 4.207671142780154 | Original Color: 408090 | Background: eeffcc | New Color: 3c7a88 | |
Fixed: .highlight .cs | Original Ratio: 4.029889370953997 | Original Color: 408090 | Background: eeffcc | New Color: 3a7784 | |
Fixed: .highlight .gr | Original Ratio: 3.7721544644042937 | Original Color: FF0000 | Background: eeffcc | New Color: e60000 | |
Fixed: .highlight .gi | Original Ratio: 3.286379568052713 | Original Color: 00A000 | Background: eeffcc | New Color: 008200 | |
Fixed: .highlight .gp | Original Ratio: 3.9855159575361934 | Original Color: c65d09 | Background: eeffcc | New Color: b75709 | |
Fixed: .highlight .nc | Original Ratio: 3.9730640741286822 | Original Color: 0e84b5 | Background: eeffcc | New Color: 0e7ba6 | |
Fixed: .highlight .no | Original Ratio: 2.348539495328476 | Original Color: 60add5 | Background: eeffcc | New Color: 2b79a1 | |
Fixed: .highlight .ni | Original Ratio: 3.8217869449326263 | Original Color: d55537 | Background: eeffcc | New Color: c54629 | |
Fixed: .highlight .nn | Original Ratio: 3.9730640741286822 | Original Color: 0e84b5 | Background: eeffcc | New Color: 0e7ba6 | |
Fixed: .highlight .nv | Original Ratio: 3.4472955697994863 | Original Color: bb60d5 | Background: eeffcc | New Color: ab40cd | |
Fixed: .highlight .w | Original Ratio: 1.8111318411907533 | Original Color: bbbbbb | Background: eeffcc | New Color: 707070 | |
Fixed: .highlight .si | Original Ratio: 2.5971599046083806 | Original Color: 70a0d0 | Background: eeffcc | New Color: 3973b7 | |
Fixed: .highlight .sx | Original Ratio: 3.9855159575361934 | Original Color: c65d09 | Background: eeffcc | New Color: b75709 | |
Fixed: .highlight .vc | Original Ratio: 3.4472955697994863 | Original Color: bb60d5 | Background: eeffcc | New Color: ab40cd | |
Fixed: .highlight .vg | Original Ratio: 3.4472955697994863 | Original Color: bb60d5 | Background: eeffcc | New Color: ab40cd | |
Fixed: .highlight .vi | Original Ratio: 3.4472955697994863 | Original Color: bb60d5 | Background: eeffcc | New Color: ab40cd | |
Fixed: .highlight .vm | Original Ratio: 3.4472955697994863 | Original Color: bb60d5 | Background: eeffcc | New Color: ab40cd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pre { line-height: 125%; } | |
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } | |
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } | |
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } | |
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } | |
.hll { background-color: #ffffcc } | |
.c { color: #408090; font-style: italic } /* Comment */ | |
.err { border: 1px solid #FF0000 } /* Error */ | |
.k { color: #007020; font-weight: bold } /* Keyword */ | |
.o { color: #666666 } /* Operator */ | |
.ch { color: #408090; font-style: italic } /* Comment.Hashbang */ | |
.cm { color: #408090; font-style: italic } /* Comment.Multiline */ | |
.cp { color: #007020 } /* Comment.Preproc */ | |
.cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ | |
.c1 { color: #408090; font-style: italic } /* Comment.Single */ | |
.cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ | |
.gd { color: #A00000 } /* Generic.Deleted */ | |
.ge { font-style: italic } /* Generic.Emph */ | |
.gr { color: #FF0000 } /* Generic.Error */ | |
.gh { color: #000080; font-weight: bold } /* Generic.Heading */ | |
.gi { color: #00A000 } /* Generic.Inserted */ | |
.go { color: #333333 } /* Generic.Output */ | |
.gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ | |
.gs { font-weight: bold } /* Generic.Strong */ | |
.gu { color: #800080; font-weight: bold } /* Generic.Subheading */ | |
.gt { color: #0044DD } /* Generic.Traceback */ | |
.kc { color: #007020; font-weight: bold } /* Keyword.Constant */ | |
.kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ | |
.kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ | |
.kp { color: #007020 } /* Keyword.Pseudo */ | |
.kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ | |
.kt { color: #902000 } /* Keyword.Type */ | |
.m { color: #208050 } /* Literal.Number */ | |
.s { color: #4070a0 } /* Literal.String */ | |
.na { color: #4070a0 } /* Name.Attribute */ | |
.nb { color: #007020 } /* Name.Builtin */ | |
.nc { color: #0e84b5; font-weight: bold } /* Name.Class */ | |
.no { color: #60add5 } /* Name.Constant */ | |
.nd { color: #555555; font-weight: bold } /* Name.Decorator */ | |
.ni { color: #d55537; font-weight: bold } /* Name.Entity */ | |
.ne { color: #007020 } /* Name.Exception */ | |
.nf { color: #06287e } /* Name.Function */ | |
.nl { color: #002070; font-weight: bold } /* Name.Label */ | |
.nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ | |
.nt { color: #062873; font-weight: bold } /* Name.Tag */ | |
.nv { color: #bb60d5 } /* Name.Variable */ | |
.ow { color: #007020; font-weight: bold } /* Operator.Word */ | |
.w { color: #bbbbbb } /* Text.Whitespace */ | |
.mb { color: #208050 } /* Literal.Number.Bin */ | |
.mf { color: #208050 } /* Literal.Number.Float */ | |
.mh { color: #208050 } /* Literal.Number.Hex */ | |
.mi { color: #208050 } /* Literal.Number.Integer */ | |
.mo { color: #208050 } /* Literal.Number.Oct */ | |
.sa { color: #4070a0 } /* Literal.String.Affix */ | |
.sb { color: #4070a0 } /* Literal.String.Backtick */ | |
.sc { color: #4070a0 } /* Literal.String.Char */ | |
.dl { color: #4070a0 } /* Literal.String.Delimiter */ | |
.sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ | |
.s2 { color: #4070a0 } /* Literal.String.Double */ | |
.se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ | |
.sh { color: #4070a0 } /* Literal.String.Heredoc */ | |
.si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ | |
.sx { color: #c65d09 } /* Literal.String.Other */ | |
.sr { color: #235388 } /* Literal.String.Regex */ | |
.s1 { color: #4070a0 } /* Literal.String.Single */ | |
.ss { color: #517918 } /* Literal.String.Symbol */ | |
.bp { color: #007020 } /* Name.Builtin.Pseudo */ | |
.fm { color: #06287e } /* Name.Function.Magic */ | |
.vc { color: #bb60d5 } /* Name.Variable.Class */ | |
.vg { color: #bb60d5 } /* Name.Variable.Global */ | |
.vi { color: #bb60d5 } /* Name.Variable.Instance */ | |
.vm { color: #bb60d5 } /* Name.Variable.Magic */ | |
.il { color: #208050 } /* Literal.Number.Integer.Long */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Pygments styles used for syntax highlighting. | |
These are based on the Sphinx style (see | |
https://github.com/sphinx-doc/sphinx/blob/master/sphinx/pygments_styles.py) | |
for light mode and the Friendly style for dark mode. | |
The styles here have been adjusted so that they are WCAG AA compatible. The | |
tool at https://github.com/mpchadwick/pygments-high-contrast-stylesheets was | |
used to identify colors that should be adjusted. | |
""" | |
from pygments.style import Style | |
from pygments.styles.friendly import FriendlyStyle | |
from pygments.styles.native import NativeStyle | |
from pygments.token import Comment, Generic, Literal, Name, Number, Text | |
class SphinxHighContrastStyle(Style): | |
""" | |
Like Sphinx (which is like friendly, but a bit darker to enhance contrast | |
on the green background) but with higher contrast colors. | |
""" | |
@property | |
def _pre_style(self): | |
# This is used instead of the default 125% so that multiline Unicode | |
# pprint output looks good | |
return 'line-height: 120%;' | |
background_color = '#eeffcc' | |
default_style = '' | |
styles = FriendlyStyle.styles | |
styles.update({ | |
# These are part of the Sphinx modification to "friendly" | |
Generic.Output: '#333', | |
Number: '#208050', | |
# These are adjusted from "friendly" (Comment is adjusted from | |
# "sphinx") to have better color contrast against the background. | |
Comment: 'italic #3c7a88', | |
Comment.Hashbang: 'italic #3c7a88', | |
Comment.Multiline: 'italic #3c7a88', | |
Comment.PreprocFile: 'italic #3c7a88', | |
Comment.Single: 'italic #3c7a88', | |
Comment.Special: '#3a7784 bg:#fff0f0', | |
Generic.Error: '#e60000', | |
Generic.Inserted: '#008200', | |
Generic.Prompt: 'bold #b75709', | |
Name.Class: 'bold #0e7ba6', | |
Name.Constant: '#2b79a1', | |
Name.Entity: 'bold #c54629', | |
Name.Namespace: 'bold #0e7ba6', | |
Name.Variable: '#ab40cd', | |
Text.Whitespace: '#707070', | |
Literal.String.Interpol: 'italic #3973b7', | |
Literal.String.Other: '#b75709', | |
Name.Variable.Class: '#ab40cd', | |
Name.Variable.Global: '#ab40cd', | |
Name.Variable.Instance: '#ab40cd', | |
Name.Variable.Magic: '#ab40cd', | |
}) | |
class NativeHighContrastStyle(NativeStyle): | |
""" | |
Like native, but with higher contrast colors. | |
""" | |
@property | |
def _pre_style(self): | |
# This is used instead of the default 125% so that multiline Unicode | |
# pprint output looks good | |
return 'line-height: 120%;' | |
styles = NativeStyle.styles | |
# These are adjusted to have better color contrast against the background | |
styles.update({ | |
Comment.Preproc: 'bold #e15a5a', | |
Comment.Special: 'bold #f75050 bg:#520000', | |
Generic.Deleted: '#e75959', | |
Generic.Error: '#e75959', | |
Generic.Traceback: '#e75959', | |
Literal.Number: '#438dc4', | |
Name.Builtin: '#2594a1', | |
# We also remove the underline here from the original style | |
Name.Class: '#548bd3', | |
Name.Function: '#548bd3', | |
# We also remove the underline here from the original style | |
Name.Namespace: '#548bd3', | |
Text.Whitespace: '#878787', | |
Literal.Number.Bin: '#438dc4', | |
Literal.Number.Float: '#438dc4', | |
Literal.Number.Hex: '#438dc4', | |
Literal.Number.Integer: '#438dc4', | |
Literal.Number.Oct: '#438dc4', | |
Name.Builtin.Pseudo: '#2594a1', | |
Name.Function.Magic: '#548bd3', | |
Literal.Number.Integer.Long: '#438dc4', | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment