2023-10-29 14:12:40 +09:00
|
|
|
import { setWasm, setCDN, Highlighter, getHighlighter as _getHighlighter } from 'shiki';
|
2023-12-30 00:18:03 +09:00
|
|
|
import { version } from '@/config.js';
|
2023-10-29 14:12:40 +09:00
|
|
|
|
2023-12-30 00:18:03 +09:00
|
|
|
setWasm(`/assets/shiki.${version}/dist/onig.wasm`);
|
|
|
|
setCDN(`/assets/shiki.${version}/`);
|
2023-10-29 14:12:40 +09:00
|
|
|
|
|
|
|
let _highlighter: Highlighter | null = null;
|
|
|
|
|
|
|
|
export async function getHighlighter(): Promise<Highlighter> {
|
|
|
|
if (!_highlighter) {
|
|
|
|
return await initHighlighter();
|
|
|
|
}
|
|
|
|
return _highlighter;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function initHighlighter() {
|
|
|
|
const highlighter = await _getHighlighter({
|
|
|
|
theme: 'dark-plus',
|
|
|
|
langs: ['js'],
|
|
|
|
});
|
|
|
|
|
|
|
|
await highlighter.loadLanguage({
|
|
|
|
path: 'languages/aiscript.tmLanguage.json',
|
|
|
|
id: 'aiscript',
|
|
|
|
scopeName: 'source.aiscript',
|
|
|
|
aliases: ['is', 'ais'],
|
|
|
|
});
|
|
|
|
|
|
|
|
_highlighter = highlighter;
|
|
|
|
|
|
|
|
return highlighter;
|
|
|
|
}
|