1- import type { ThemeRegistrationRaw } from 'shiki'
2-
31/**
4- * Sim's syntax theme for docs code blocks.
5- *
6- * The platform highlights code with PrismJS through `@sim/emcn`'s `Code` component, whose
7- * token colors live in `packages/emcn/src/components/code/code.css`. Docs highlight with
8- * Shiki, which is TextMate-scoped rather than Prism-tokenized, so parity has to be
9- * expressed as a scope-to-color mapping rather than a shared stylesheet. The palette follows
10- * `code.css` in light mode, with darker hues for readable contrast. Dark mode consumes the
2+ * Sim's syntax theme for docs code blocks. The scope mapping is shared with the app in
3+ * `@sim/emcn/syntax-theme`; docs supply their own palettes. Light mode
4+ * follows `code.css` with darker hues for readable contrast, and dark mode consumes the
115 * docs semantic tokens so authored MDX and generated examples share the reading palette.
12- *
13- * The mapping was derived by highlighting the same snippets through both engines and
14- * comparing output. Two places where the grammars genuinely disagree, and the choice made:
15- *
16- * - Prism only colors a shell command when it recognises the binary, so `npm` highlights
17- * but `sim` does not. TextMate scopes the first word of a statement as the command
18- * regardless, so `sim` highlights too. Shiki's reading is the correct one and is kept.
19- * - TextMate scopes every bare shell argument as `string.unquoted.argument`, which would
20- * paint most of a command line in the string color. Prism leaves those plain, so the
21- * scope is pinned back to the base foreground and only genuinely quoted strings carry
22- * the string color.
23- *
24- * Bare `variable` is deliberately unmapped. TextMate scopes declared JavaScript
25- * identifiers as `variable.other.*`, and coloring those would make JS and TS far busier
26- * than the platform editor, which leaves them at the base foreground. Only the things
27- * Prism actually calls out — object and config keys, shell flags and shell expansions —
28- * are mapped to the variable color.
296 */
7+ import { buildSyntaxTheme , type SyntaxColors } from '@sim/emcn/syntax-theme'
308
319/** Light-mode platform hues adjusted to meet WCAG AA text contrast on the code surface. */
32- const LIGHT = {
10+ const LIGHT : SyntaxColors = {
3311 /** `--text-primary` — the platform's base code foreground. */
3412 foreground : '#1a1a1a' ,
3513 /** `--surface-5` — the fill `chipFieldSurfaceClass` puts under a code surface. */
@@ -43,10 +21,10 @@ const LIGHT = {
4321 function : '#854d0e' ,
4422 regex : '#be123c' ,
4523 deleted : '#b91c1c' ,
46- } as const
24+ }
4725
4826/** Dark syntax roles resolve through the shared docs theme, including portal surfaces. */
49- const DARK = {
27+ const DARK : SyntaxColors = {
5028 foreground : 'var(--docs-text)' ,
5129 background : 'var(--docs-surface)' ,
5230 comment : 'var(--docs-green)' ,
@@ -58,138 +36,10 @@ const DARK = {
5836 function : 'var(--docs-orange)' ,
5937 regex : 'var(--docs-red)' ,
6038 deleted : 'var(--docs-red)' ,
61- } as const
62-
63- type TokenColors = typeof LIGHT | typeof DARK
64-
65- /**
66- * Builds a Shiki theme from one palette. Scope order matters: TextMate resolves a token by
67- * longest matching scope, so the narrower entries below (`string.unquoted.argument`,
68- * `keyword.operator`) intentionally follow and override the broader ones.
69- */
70- function buildTheme ( name : string , type : 'light' | 'dark' , c : TokenColors ) : ThemeRegistrationRaw {
71- return {
72- name,
73- type,
74- settings : [
75- { settings : { background : c . background , foreground : c . foreground } } ,
76-
77- /** Prism `comment` / `block-comment` / `prolog` / `doctype` / `cdata`. */
78- {
79- scope : [ 'comment' , 'punctuation.definition.comment' , 'string.comment' ] ,
80- settings : { foreground : c . comment } ,
81- } ,
82-
83- /** Prism `keyword` / `atrule` — plus TextMate's storage scopes, which Prism folds into keywords. */
84- {
85- scope : [
86- 'keyword' ,
87- 'keyword.control' ,
88- 'keyword.other' ,
89- 'storage' ,
90- 'storage.type' ,
91- 'storage.modifier' ,
92- 'meta.import keyword' ,
93- 'meta.export keyword' ,
94- ] ,
95- settings : { foreground : c . keyword } ,
96- } ,
97-
98- /** Prism `function` and `class-name`. */
99- {
100- scope : [
101- 'entity.name.function' ,
102- 'entity.name.command' ,
103- 'support.function' ,
104- 'meta.function-call.generic' ,
105- 'entity.name.class' ,
106- 'entity.name.type' ,
107- 'support.class' ,
108- 'support.type' ,
109- ] ,
110- settings : { foreground : c . function } ,
111- } ,
112-
113- /**
114- * Prism `property` / `attr-name` / `variable` — object and config keys, markup
115- * attributes, shell flags and shell expansions. Bare `variable` is excluded on
116- * purpose; see the module docblock.
117- */
118- {
119- scope : [
120- 'support.type.property-name' ,
121- 'meta.object-literal.key' ,
122- 'entity.name.tag.yaml' ,
123- 'entity.other.attribute-name' ,
124- 'constant.other.option' ,
125- 'variable.other.normal' ,
126- 'variable.other.special' ,
127- 'punctuation.definition.variable' ,
128- ] ,
129- settings : { foreground : c . variable } ,
130- } ,
131-
132- /** Prism `number` / `boolean` / `constant` / `tag`. */
133- {
134- scope : [
135- 'constant.numeric' ,
136- 'constant.language' ,
137- 'constant.character' ,
138- 'support.constant' ,
139- 'entity.name.tag' ,
140- 'variable.language' ,
141- ] ,
142- settings : { foreground : c . constant } ,
143- } ,
144-
145- /** Prism `string` / `char` / `inserted`. */
146- {
147- scope : [
148- 'string' ,
149- 'string.quoted' ,
150- 'string.template' ,
151- 'punctuation.definition.string' ,
152- 'markup.inserted' ,
153- ] ,
154- settings : { foreground : c . string } ,
155- } ,
156-
157- /**
158- * Bare shell arguments. TextMate calls these strings; Prism leaves them plain, and
159- * plain is what keeps a command line readable. Declared after `string` so it wins.
160- */
161- { scope : [ 'string.unquoted.argument' ] , settings : { foreground : c . foreground } } ,
162-
163- /** Prism `punctuation` / `operator` / `entity` / `symbol`. */
164- {
165- scope : [
166- 'punctuation' ,
167- 'meta.brace' ,
168- 'keyword.operator' ,
169- 'punctuation.separator' ,
170- 'punctuation.terminator' ,
171- 'punctuation.accessor' ,
172- ] ,
173- settings : { foreground : c . punctuation } ,
174- } ,
175-
176- /** Prism `regex` / `important`. */
177- {
178- scope : [ 'string.regexp' , 'constant.regexp' , 'keyword.other.important' ] ,
179- settings : { foreground : c . regex } ,
180- } ,
181-
182- /** Prism `deleted`, plus TextMate's invalid scopes. */
183- {
184- scope : [ 'markup.deleted' , 'invalid' , 'invalid.illegal' ] ,
185- settings : { foreground : c . deleted } ,
186- } ,
187- ] ,
188- }
18939}
19040
191- const simShikiLight = buildTheme ( 'sim-light' , 'light' , LIGHT )
192- const simShikiDark = buildTheme ( 'sim-dark' , 'dark' , DARK )
41+ const simShikiLight = buildSyntaxTheme ( 'sim-light' , 'light' , LIGHT )
42+ const simShikiDark = buildSyntaxTheme ( 'sim-dark' , 'dark' , DARK )
19343
19444/** Shared syntax palette for build-time MDX and generated API examples. */
19545export const simShikiOptions = {
0 commit comments