|
1 | 1 | import type { MaybeRef } from '@vueuse/core'
|
2 |
| -import type { BundledLanguage, Highlighter } from 'shiki' |
3 |
| -import { createHighlighter } from 'shiki' |
| 2 | +import type { HighlighterCore } from 'shiki' |
| 3 | +import { createHighlighterCore } from 'shiki/core' |
| 4 | +import { createJavaScriptRegexEngine } from 'shiki/engine/javascript' |
4 | 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 | 10 | export async function loadShiki() {
|
10 | 11 | // Only loading when needed
|
11 |
| - shiki.value = await createHighlighter({ |
| 12 | + shiki.value = await createHighlighterCore({ |
12 | 13 | themes: [
|
13 |
| - 'vitesse-dark', |
14 |
| - 'vitesse-light', |
| 14 | + import('@shikijs/themes/vitesse-light'), |
| 15 | + import('@shikijs/themes/vitesse-dark'), |
15 | 16 | ],
|
16 | 17 | langs: [
|
17 |
| - 'html', |
18 |
| - 'json', |
19 |
| - 'bash', |
| 18 | + import('@shikijs/langs/json'), |
| 19 | + import('@shikijs/langs/html'), |
| 20 | + import('@shikijs/langs/bash'), |
20 | 21 | Object.freeze({
|
21 | 22 | displayName: 'robots.txt',
|
22 | 23 | name: 'robots-txt',
|
@@ -70,11 +71,12 @@ export async function loadShiki() {
|
70 | 71 | scopeName: 'text.robots-txt',
|
71 | 72 | }),
|
72 | 73 | ],
|
| 74 | + engine: createJavaScriptRegexEngine(), |
73 | 75 | })
|
74 | 76 | return shiki.value
|
75 | 77 | }
|
76 | 78 |
|
77 |
| -export function renderCodeHighlight(code: MaybeRef<string>, lang?: BundledLanguage | 'robots-txt') { |
| 79 | +export function renderCodeHighlight(code: MaybeRef<string>, lang: 'json' | 'html' | 'bash' | 'robots-txt') { |
78 | 80 | return computed(() => {
|
79 | 81 | const colorMode = devtools.value?.colorMode || 'light'
|
80 | 82 | return shiki.value!.codeToHtml(toValue(code), {
|
|
0 commit comments