scripts/composition-theme.ts
- Files
- scripts
- composition-theme.ts
1import type { LanguageRegistration } from "shiki";
2import { createHighlighterCoreSync } from "shiki/core";
3import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
4import light from "shiki/themes/github-light.mjs";
5import dark from "shiki/themes/github-dark.mjs";
6
7// The guide owns this small notation. It is not a TypeScript API declaration.
8export const grammar = {
9 repository: {},
10 name: "axiomatic-composition",
11 scopeName: "source.axiomatic",
12 patterns: [
13 {
14 name: "string.quoted.double.axiomatic",
15 begin: '"',
16 end: '"',
17 patterns: [
18 { name: "constant.character.escape.axiomatic", match: "\\\\." },
19 ],
20 },
21 {
22 name: "entity.name.function.axiomatic",
23 match: "\\b[A-Z][A-Za-z]*(?=\\()",
24 },
25 ],
26} satisfies LanguageRegistration;
27const highlighter = createHighlighterCoreSync({
28 themes: [light, dark],
29 langs: [grammar],
30 engine: createJavaScriptRegexEngine(),
31});
32export function compositionTokens(source: string) {
33 return highlighter.codeToTokensWithThemes(source, {
34 lang: "axiomatic-composition",
35 themes: { light: "github-light", dark: "github-dark" },
36 });
37}