2024-02-02 07:05:18 +01:00
|
|
|
import { getHighlighterCore, loadWasm } from 'shiki/core';
|
|
|
|
import darkPlus from 'shiki/themes/dark-plus.mjs';
|
|
|
|
import type { Highlighter, LanguageRegistration } from 'shiki';
|
2023-10-29 06:12:40 +01:00
|
|
|
|
|
|
|
let _highlighter: Highlighter | null = null;
|
|
|
|
|
|
|
|
export async function getHighlighter(): Promise<Highlighter> {
|
|
|
|
if (!_highlighter) {
|
|
|
|
return await initHighlighter();
|
|
|
|
}
|
|
|
|
return _highlighter;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function initHighlighter() {
|
2024-02-02 07:05:18 +01:00
|
|
|
const aiScriptGrammar = await import('aiscript-vscode/aiscript/syntaxes/aiscript.tmLanguage.json');
|
|
|
|
|
|
|
|
await loadWasm(import('shiki/onig.wasm?init'));
|
2023-10-29 06:12:40 +01:00
|
|
|
|
2024-02-02 07:05:18 +01:00
|
|
|
const highlighter = await getHighlighterCore({
|
|
|
|
themes: [darkPlus],
|
|
|
|
langs: [
|
|
|
|
import('shiki/langs/javascript.mjs'),
|
|
|
|
{
|
|
|
|
aliases: ['is', 'ais'],
|
|
|
|
...aiScriptGrammar.default,
|
|
|
|
} as unknown as LanguageRegistration,
|
|
|
|
],
|
2023-10-29 06:12:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
_highlighter = highlighter;
|
|
|
|
|
|
|
|
return highlighter;
|
|
|
|
}
|