Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Code

527 commit(s) on main

Put job execution behind an interface Keenan Nemetz · 2h ago de3eec16
history blame raw 4.2 KiB
1#!/usr/bin/env python3
2"""Write the Pygments token colours used by the documentation theme.
3
4The documentation build runs Markdown through mkdocs' codehilite extension, which
5uses Pygments. This script maps Pygments' token classes onto the same Everforest
6dark/medium accents as server/web/static/everforest.css, so a fenced block in the
7docs looks like a code block in the forge.
8
9Run it after changing the palette or the token mapping:
10
11 python3 scripts/gen-pygments-css.py
12"""
13
14from pathlib import Path
15
16from pygments.formatters import HtmlFormatter
17from pygments.style import Style
18from pygments.token import (
19 Comment,
20 Error,
21 Generic,
22 Keyword,
23 Literal,
24 Name,
25 Number,
26 Operator,
27 Punctuation,
28 String,
29 Text,
30 Whitespace,
31)
32
33OUT = Path(__file__).resolve().parent.parent / "docs-theme/assets/pygments.css"
34
35HEADER = """/* Pygments token colours for the documentation theme.
36
37 Generated by scripts/gen-pygments-css.py from the Everforest dark/medium
38 palette used by server/web/static/everforest.css. The selectors are the
39 classes the codehilite Markdown extension emits. Backgrounds and spacing live
40 in docs.css so the code block matches the forge's panels. */
41
42"""
43
44
45class EverforestDarkMedium(Style):
46 """Everforest dark/medium mapped onto Pygments' token classes."""
47
48 background_color = "#2d353b"
49 highlight_color = "#3d484d"
50 default_style = ""
51
52 styles = {
53 Text: "#d3c6aa",
54 Whitespace: "#d3c6aa",
55 Error: "#e67e80",
56 Comment: "italic #859289",
57 Comment.Preproc: "#e69875",
58 Comment.Special: "italic #9da9a0",
59 Keyword: "#e67e80",
60 Keyword.Constant: "#d699b6",
61 Keyword.Declaration: "#e67e80",
62 Keyword.Namespace: "#e67e80",
63 Keyword.Reserved: "#e67e80",
64 Keyword.Type: "#dbbc7f",
65 Operator: "#e69875",
66 Operator.Word: "#e67e80",
67 Punctuation: "#9da9a0",
68 Name: "#d3c6aa",
69 Name.Attribute: "#dbbc7f",
70 Name.Builtin: "#dbbc7f",
71 Name.Builtin.Pseudo: "#d699b6",
72 Name.Class: "#dbbc7f",
73 Name.Constant: "#d699b6",
74 Name.Decorator: "#e69875",
75 Name.Entity: "#e69875",
76 Name.Exception: "#e67e80",
77 Name.Function: "#a7c080",
78 Name.Function.Magic: "#a7c080",
79 Name.Label: "#9da9a0",
80 Name.Namespace: "#d3c6aa",
81 Name.Property: "#dbbc7f",
82 Name.Tag: "#e67e80",
83 Name.Variable: "#d3c6aa",
84 Name.Variable.Class: "#d3c6aa",
85 Name.Variable.Global: "#d3c6aa",
86 Name.Variable.Instance: "#d3c6aa",
87 Name.Variable.Magic: "#d3c6aa",
88 Literal: "#d699b6",
89 Literal.Date: "#a7c080",
90 Number: "#d699b6",
91 Number.Float: "#d699b6",
92 Number.Hex: "#d699b6",
93 Number.Integer: "#d699b6",
94 Number.Integer.Long: "#d699b6",
95 Number.Oct: "#d699b6",
96 String: "#a7c080",
97 String.Affix: "#dbbc7f",
98 String.Backtick: "#a7c080",
99 String.Char: "#a7c080",
100 String.Delimiter: "#9da9a0",
101 String.Doc: "italic #859289",
102 String.Double: "#a7c080",
103 String.Escape: "#e69875",
104 String.Heredoc: "#a7c080",
105 String.Interpol: "#e69875",
106 String.Other: "#a7c080",
107 String.Regex: "#d699b6",
108 String.Single: "#a7c080",
109 String.Symbol: "#d699b6",
110 Generic.Deleted: "#e67e80",
111 Generic.Emph: "italic",
112 Generic.Error: "#e67e80",
113 Generic.Heading: "bold #a7c080",
114 Generic.Inserted: "#a7c080",
115 Generic.Output: "#9da9a0",
116 Generic.Prompt: "#859289",
117 Generic.Strong: "bold",
118 Generic.Subheading: "bold #a7c080",
119 Generic.Traceback: "#e67e80",
120 }
121
122
123def main() -> None:
124 css = HtmlFormatter(style=EverforestDarkMedium).get_style_defs(".codehilite")
125 # The formatter also emits rules for Pygments' optional line-number table and
126 # a global `pre` line-height. Neither is part of this theme: docs.css owns the
127 # block's spacing and the theme has no line numbers.
128 lines = [
129 line
130 for line in css.splitlines()
131 if not line.startswith(("pre {", "td.linenos", "span.linenos"))
132 ]
133 OUT.write_text(HEADER + "\n".join(lines) + "\n", encoding="utf-8")
134
135
136if __name__ == "__main__":
137 main()
138