refactor: migrate from shikiji to shiki v1 (#2591)

This commit is contained in:
ocavue 2024-02-15 15:43:09 +08:00 committed by GitHub
parent 40415f34a4
commit 8eb6b2378a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 37 deletions

View file

@ -0,0 +1,22 @@
import { type Parser, createParser } from 'prosemirror-highlight/shiki'
import type { BuiltinLanguage } from 'shiki'
let parser: Parser | undefined
export const shikiParser: Parser = (options) => {
const lang = options.language ?? 'text'
// Register the language if it's not yet registered
const { highlighter, promise } = useHighlighter(lang as BuiltinLanguage)
// If the highlighter or the language is not available, return a promise that
// will resolve when it's ready. When the promise resolves, the editor will
// re-parse the code block.
if (!highlighter)
return promise ?? []
if (!parser)
parser = createParser(highlighter)
return parser(options)
}