refactor: migrate from shiki to shikiji (#2520)

This commit is contained in:
ocavue 2023-12-21 02:54:40 +08:00 committed by GitHub
parent e63473a5f8
commit 74138a9a58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 124 additions and 223 deletions

View file

@ -0,0 +1,20 @@
import { type Parser, createParser } from 'prosemirror-highlight/shikiji'
import type { BuiltinLanguage } from 'shikiji/langs'
let parser: Parser | undefined
export const shikijiParser: Parser = (options) => {
const lang = options.language ?? 'text'
// Register the language if it's not yet registered
const highlighter = useHighlighter(lang as BuiltinLanguage)
// If the language is not loaded, we return an empty set of decorations
if (!highlighter)
return []
if (!parser)
parser = createParser(highlighter)
return parser(options)
}