chore: refactor markdown render for workers
5ea358ae
1 file(s) · +26 −21
| 1 | 1 | import MarkdownIt from "markdown-it"; |
|
| 2 | - | import { createHighlighter, type ThemeRegistrationRaw } from "shiki"; |
|
| 2 | + | import { createHighlighterCore, type ThemeRegistrationRaw } from "shiki/core"; |
|
| 3 | + | import { createJavaScriptRegexEngine } from "shiki/engine/javascript"; |
|
| 4 | + | import { bundledLanguages } from "shiki"; |
|
| 3 | 5 | import darkmatter from "../../darkmatter.json"; |
|
| 6 | + | ||
| 7 | + | const LANGS = [ |
|
| 8 | + | "javascript", |
|
| 9 | + | "typescript", |
|
| 10 | + | "jsx", |
|
| 11 | + | "tsx", |
|
| 12 | + | "python", |
|
| 13 | + | "bash", |
|
| 14 | + | "shell", |
|
| 15 | + | "json", |
|
| 16 | + | "html", |
|
| 17 | + | "css", |
|
| 18 | + | "rust", |
|
| 19 | + | "go", |
|
| 20 | + | "markdown", |
|
| 21 | + | "yaml", |
|
| 22 | + | "toml", |
|
| 23 | + | "text", |
|
| 24 | + | "lua", |
|
| 25 | + | ] as const; |
|
| 4 | 26 | ||
| 5 | 27 | export async function createMarkdownRenderer(): Promise<MarkdownIt> { |
|
| 6 | - | const highlighter = await createHighlighter({ |
|
| 28 | + | const highlighter = await createHighlighterCore({ |
|
| 7 | 29 | themes: [darkmatter as unknown as ThemeRegistrationRaw], |
|
| 8 | - | langs: [ |
|
| 9 | - | "javascript", |
|
| 10 | - | "typescript", |
|
| 11 | - | "jsx", |
|
| 12 | - | "tsx", |
|
| 13 | - | "python", |
|
| 14 | - | "bash", |
|
| 15 | - | "shell", |
|
| 16 | - | "json", |
|
| 17 | - | "html", |
|
| 18 | - | "css", |
|
| 19 | - | "rust", |
|
| 20 | - | "go", |
|
| 21 | - | "markdown", |
|
| 22 | - | "yaml", |
|
| 23 | - | "toml", |
|
| 24 | - | "text", |
|
| 25 | - | "lua", |
|
| 26 | - | ], |
|
| 30 | + | langs: LANGS.map((l) => bundledLanguages[l]), |
|
| 31 | + | engine: createJavaScriptRegexEngine(), |
|
| 27 | 32 | }); |
|
| 28 | 33 | ||
| 29 | 34 | let md: MarkdownIt; |