Commit 08efdf6
committed
docs(highlight): overhaul syntax highlighting grammar and color palette
Rewrite radon-highlight.js and extra.css to use the same token color
palette as radon-project.github.io and the Radon REPL terminal.
radon-highlight.js:
- Inject !important CSS overrides at runtime to beat Material for MkDocs'
bundled hljs theme rules, which override standard class names (.hljs-keyword,
.hljs-string, .hljs-number, .hljs-comment, .hljs-operator) at higher cascade
order. Non-standard names (.hljs-builtin, .hljs-fncall, .hljs-special,
.hljs-punctuation) do not need !important.
- Rewrite grammar rule order (first-match wins): multi-line comment (#! … !#)
→ single-line comment (#) → string → builtin → keyword → number → special
→ fncall → operator → punctuation.
- Add multi-line comment rule (#! … !#) before single-line so #! is not
consumed by the # rule.
- Expand keyword list from 6 to 30+ keywords sourced from core/tokens.py
KEYWORDS list. Add 'as', 'elif', 'for', 'while', 'return', 'import',
'from', 'in', 'and', 'or', 'not', 'try', 'catch', 'raise', 'break',
'continue', 'const', 'static', 'assert', 'switch', 'case', 'default',
'fallthrough', 'fallout', 'del', 'step', 'to'. Remove invalid 'end'.
Add 'null', 'true', 'false', 'this', '__constructor__' as keyword-like.
- Add builtin class sourced from create_global_symbol_table() in
core/builtin_funcs.py. Includes all 37 built-in functions plus 5 built-in
classes: File, String, Json, Requests, builtins.
- Add fncall rule using lookahead (?=\s*\() so ( stays outside the span
and falls through to punctuation.
- Add punctuation rule for {}()[],.;:
- Expand operator regex to cover multi-char operators (->, ++, --, ==, !=,
<=, >=, +=, -=, *=, /=, %=) before single-char to prevent partial matches.
- Fix number regex to also match floats (\b\d+(?:\.\d+)?\b).
- Remove invalid hljs.IMMEDIATE_RE reference from string rule.
- Replace hljs.highlightAll() with explicit querySelectorAll targeting
.language-text.highlight pre code blocks (MkDocs Pygments TextLexer
fallback when no 'rn' lexer is registered) and re-highlight them as 'rn'
using block.textContent to strip Pygments line-number anchors.
extra.css:
- Replace all token colors with the new palette matching radon-project.github.io.
- Add !important on .hljs-keyword, .hljs-string, .hljs-number, .hljs-comment,
.hljs-operator as a CSS fallback matching the runtime JS injection.
- Add new rules: .hljs-builtin (#34d399), .hljs-punctuation (#94a3b8).
- Remove .hljs-function (replaced by .hljs-fncall + .hljs-special, both #c084fc).
- Set .hljs-identifier to inherit (no coloring for plain identifiers).
Token palette:
keyword #7dd3fc sky-blue bold
builtin #34d399 emerald
string #a3e635 lime-green
number #fb923c orange
operator #f87171 salmon
punctuation #94a3b8 slate-gray
comment #5c6591 slate-purple italic
fncall #c084fc violet
special #c084fc violet1 parent 8057ec5 commit 08efdf6
2 files changed
Lines changed: 86 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
5 | 21 | | |
6 | 22 | | |
7 | 23 | | |
| 24 | + | |
| 25 | + | |
8 | 26 | | |
9 | | - | |
10 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
11 | 30 | | |
| 31 | + | |
12 | 32 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
21 | 36 | | |
| 37 | + | |
22 | 38 | | |
23 | | - | |
24 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
25 | 43 | | |
| 44 | + | |
| 45 | + | |
26 | 46 | | |
27 | | - | |
28 | | - | |
| 47 | + | |
| 48 | + | |
29 | 49 | | |
30 | 50 | | |
31 | | - | |
32 | | - | |
| 51 | + | |
| 52 | + | |
33 | 53 | | |
34 | 54 | | |
35 | | - | |
36 | | - | |
| 55 | + | |
| 56 | + | |
37 | 57 | | |
| 58 | + | |
38 | 59 | | |
39 | | - | |
40 | | - | |
| 60 | + | |
| 61 | + | |
41 | 62 | | |
| 63 | + | |
42 | 64 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 65 | + | |
| 66 | + | |
46 | 67 | | |
| 68 | + | |
47 | 69 | | |
48 | | - | |
49 | | - | |
| 70 | + | |
| 71 | + | |
50 | 72 | | |
51 | 73 | | |
52 | | - | |
53 | | - | |
| 74 | + | |
| 75 | + | |
54 | 76 | | |
55 | 77 | | |
56 | 78 | | |
57 | 79 | | |
58 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
59 | 96 | | |
60 | 97 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
27 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
| 30 | + | |
| 31 | + | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
42 | | - | |
| 43 | + | |
43 | 44 | | |
0 commit comments