|
1 |
| -import type { Highlighter, BundledLanguage } from 'shiki' |
2 |
| -import { createHighlighter } from 'shiki' |
3 |
| -import { computed, ref, toValue } from 'vue' |
4 | 1 | import type { MaybeRef } from '@vueuse/core'
|
| 2 | +import type { HighlighterCore } from 'shiki' |
| 3 | +import { createHighlighterCore } from 'shiki/core' |
| 4 | +import { createJavaScriptRegexEngine } from 'shiki/engine/javascript' |
| 5 | +import { computed, ref, toValue } from 'vue' |
5 | 6 | import { devtools } from './rpc'
|
6 | 7 |
|
7 |
| -export const shiki = ref<Highlighter>() |
| 8 | +export const shiki = ref<HighlighterCore>() |
8 | 9 |
|
9 |
| -export function loadShiki() { |
10 |
| - // Only loading when needed |
11 |
| - return createHighlighter({ |
| 10 | +export async function loadShiki() { |
| 11 | + shiki.value = await createHighlighterCore({ |
12 | 12 | themes: [
|
13 |
| - 'vitesse-dark', |
14 |
| - 'vitesse-light', |
| 13 | + import('@shikijs/themes/vitesse-light'), |
| 14 | + import('@shikijs/themes/vitesse-dark'), |
15 | 15 | ],
|
16 | 16 | langs: [
|
17 |
| - 'css', |
18 |
| - 'javascript', |
19 |
| - 'typescript', |
20 |
| - 'html', |
21 |
| - 'vue', |
22 |
| - 'vue-html', |
23 |
| - 'bash', |
24 |
| - 'diff', |
| 17 | + import('@shikijs/langs/javascript'), |
25 | 18 | ],
|
26 |
| - }).then((i) => { |
27 |
| - shiki.value = i |
| 19 | + engine: createJavaScriptRegexEngine(), |
28 | 20 | })
|
| 21 | + |
| 22 | + return shiki.value |
29 | 23 | }
|
30 | 24 |
|
31 |
| -export function renderCodeHighlight(code: MaybeRef<string>, lang: BundledLanguage) { |
| 25 | +export function renderCodeHighlight(code: MaybeRef<string>, lang: 'javascript') { |
32 | 26 | return computed(() => {
|
33 | 27 | const colorMode = devtools.value?.colorMode || 'light'
|
34 |
| - return shiki.value!.codeToHtml(toValue(code), { |
| 28 | + return shiki.value!.codeToHtml(toValue(code) || '', { |
35 | 29 | lang,
|
36 | 30 | theme: colorMode === 'dark' ? 'vitesse-dark' : 'vitesse-light',
|
37 | 31 | }) || ''
|
|
0 commit comments