|
1 | 1 | import * as monaco from 'monaco-editor-core'
|
2 |
| -import { createHighlighterCore } from 'shiki/core' |
| 2 | +import { createHighlighterCoreSync } from 'shiki/core' |
| 3 | +import { createJavaScriptRegexEngine } from 'shiki/engine-javascript.mjs' |
3 | 4 | import { shikiToMonaco } from '@shikijs/monaco'
|
4 | 5 |
|
5 | 6 | import langVue from 'shiki/langs/vue.mjs'
|
| 7 | +import langTsx from 'shiki/langs/tsx.mjs' |
| 8 | +import langJsx from 'shiki/langs/jsx.mjs' |
6 | 9 | import themeDark from 'shiki/themes/dark-plus.mjs'
|
7 | 10 | import themeLight from 'shiki/themes/light-plus.mjs'
|
8 | 11 |
|
9 |
| -export async function registerHighlighter() { |
10 |
| - const highlighter = await createHighlighterCore({ |
11 |
| - themes: [themeDark, themeLight], |
12 |
| - langs: [langVue], |
13 |
| - loadWasm: import('shiki/wasm'), |
14 |
| - }) |
15 |
| - monaco.languages.register({ id: 'vue' }) |
16 |
| - shikiToMonaco(highlighter, monaco) |
| 12 | +let registered = false |
| 13 | +export function registerHighlighter() { |
| 14 | + if (!registered) { |
| 15 | + const highlighter = createHighlighterCoreSync({ |
| 16 | + themes: [themeDark, themeLight], |
| 17 | + langs: [langVue, langTsx, langJsx], |
| 18 | + engine: createJavaScriptRegexEngine(), |
| 19 | + }) |
| 20 | + monaco.languages.register({ id: 'vue' }) |
| 21 | + shikiToMonaco(highlighter, monaco) |
| 22 | + registered = true |
| 23 | + } |
| 24 | + |
17 | 25 | return {
|
18 | 26 | light: themeLight.name!,
|
19 | 27 | dark: themeDark.name!,
|
|
0 commit comments