-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
highlight.ts
38 lines (29 loc) · 1.17 KB
/
highlight.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { Highlighter, ILanguageRegistration } from 'shiki'
import { getHighlighter, setOnigasmWASM } from 'shiki'
import onigasm from 'onigasm/lib/onigasm.wasm?url'
import shikiCyTheme from '../public/shiki/themes/cypress.theme.json'
const langJSONFilesArray = import.meta.globEager('../public/shiki/languages/*.tmLanguage.json')
// Convert to the format shiki needs for language customization.
// @see https://github.com/shikijs/shiki/blob/main/docs/languages.md
const langs: ILanguageRegistration[] = Object.values(langJSONFilesArray).map((grammar: any) => {
return {
grammar,
id: grammar.name,
scopeName: grammar.scopeName,
}
})
setOnigasmWASM(onigasm)
let highlighter: Highlighter
export type CyLangType = 'typescript' | 'javascript' | 'ts' | 'js' | 'css' | 'jsx' | 'tsx' | 'json' | 'yaml' | 'html' | 'plaintext' | 'txt' | 'text' | 'vue' | string
export const langsSupported = langs.map((lang: ILanguageRegistration) => lang.id)
export async function initHighlighter () {
if (highlighter) {
return
}
highlighter = await getHighlighter({
theme: shikiCyTheme as any,
langs,
})
}
const inheritAttrs = false
export { highlighter, inheritAttrs }