| 1 | import pierreDark from "@pierre/theme/pierre-dark"; |
| 2 | import pierreLight from "@pierre/theme/pierre-light |
| 3 | import { |
| 4 | bundledLanguages, |
| 5 | codeToTokens, |
| 6 | type BundledLanguage, |
| 7 | type ThemeRegistrationRaw, |
| 8 | } from "shiki"; |
| 9 | |
| 10 | import { APP_THEMES } |
| 11 | |
| 12 | // the pierre themes ship as frozen TextMate objects, which shiki loads and caches by their own `name`; the rest are bundled names. keys line up with the `--shiki-<id>` selectors in globals.css. |
| 13 | const THEMES = Object |
| 14 | APP_THEMES.map((t |
| 15 | t.id, |
| 16 | t.id === |
| 17 | ? (pierreLight as |
| 18 | : t.id |
| 19 | ? (pierreDark as |
| 20 | : t.shiki, |
| 21 | ]), |
| 22 | ); |
| 23 | |
| 24 | const LANGUAGE_BY_NAME: Record |
| 25 | dockerfile: "docker", |
| 26 | makefile: "make", |
| 27 | gemfile: "ruby", |
| 28 | rakefile: "ruby", |
| 29 | }; |
| 30 | |
| 31 | function languageFor(filename: |
| 32 | const name = |
| 33 | if (name in |
| 34 | |
| 35 | const extension = |
| 36 | return extension in |
| 37 | ? (extension as |
| 38 | : "text"; |
| 39 | } |
| 40 | |
| 41 | /** Tokens per line, coloured for every app theme at once. Render them inside `[data-shiki]`, which picks the active theme's colour. */ |
| 42 | export async function highlightLines |
| 43 | const { tokens |
| 44 | lang: languageFor(filename |
| 45 | themes: THEMES, |
| 46 | defaultColor: false, |
| 47 | }); |
| 48 | return tokens; |
| 49 | } |