|
1 | 1 | import { marked, type Tokens } from 'marked' |
2 | 2 | import sanitizeHtml from 'sanitize-html' |
3 | | -import { createHighlighter, type Highlighter } from 'shiki' |
| 3 | +import { createHighlighterCore, type HighlighterCore } from 'shiki/core' |
| 4 | +import { createJavaScriptRegexEngine } from 'shiki/engine/javascript' |
4 | 5 | import { hasProtocol } from 'ufo' |
5 | 6 |
|
6 | 7 | // only allow h3-h6 since we shift README headings down by 2 levels |
@@ -40,33 +41,36 @@ const ALLOWED_ATTR: Record<string, string[]> = { |
40 | 41 | // GitHub-style callout types |
41 | 42 | // Format: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION] |
42 | 43 |
|
43 | | -// Singleton highlighter instance |
44 | | -let highlighter: Highlighter | null = null |
| 44 | +// Singleton highlighter instance using JavaScript engine (no WASM needed) |
| 45 | +let highlighter: HighlighterCore | null = null |
45 | 46 |
|
46 | | -async function getHighlighter(): Promise<Highlighter> { |
| 47 | +async function getHighlighter(): Promise<HighlighterCore> { |
47 | 48 | if (!highlighter) { |
48 | | - highlighter = await createHighlighter({ |
49 | | - themes: ['github-dark'], |
| 49 | + highlighter = await createHighlighterCore({ |
| 50 | + themes: [ |
| 51 | + import('@shikijs/themes/github-dark'), |
| 52 | + ], |
50 | 53 | langs: [ |
51 | | - 'javascript', |
52 | | - 'typescript', |
53 | | - 'json', |
54 | | - 'html', |
55 | | - 'css', |
56 | | - 'bash', |
57 | | - 'shell', |
58 | | - 'markdown', |
59 | | - 'yaml', |
60 | | - 'vue', |
61 | | - 'jsx', |
62 | | - 'tsx', |
63 | | - 'diff', |
64 | | - 'sql', |
65 | | - 'graphql', |
66 | | - 'python', |
67 | | - 'rust', |
68 | | - 'go', |
| 54 | + import('@shikijs/langs/javascript'), |
| 55 | + import('@shikijs/langs/typescript'), |
| 56 | + import('@shikijs/langs/json'), |
| 57 | + import('@shikijs/langs/html'), |
| 58 | + import('@shikijs/langs/css'), |
| 59 | + import('@shikijs/langs/bash'), |
| 60 | + import('@shikijs/langs/shell'), |
| 61 | + import('@shikijs/langs/markdown'), |
| 62 | + import('@shikijs/langs/yaml'), |
| 63 | + import('@shikijs/langs/vue'), |
| 64 | + import('@shikijs/langs/jsx'), |
| 65 | + import('@shikijs/langs/tsx'), |
| 66 | + import('@shikijs/langs/diff'), |
| 67 | + import('@shikijs/langs/sql'), |
| 68 | + import('@shikijs/langs/graphql'), |
| 69 | + import('@shikijs/langs/python'), |
| 70 | + import('@shikijs/langs/rust'), |
| 71 | + import('@shikijs/langs/go'), |
69 | 72 | ], |
| 73 | + engine: createJavaScriptRegexEngine(), |
70 | 74 | }) |
71 | 75 | } |
72 | 76 | return highlighter |
|
0 commit comments