fix: trigger code block highlighting when the highlighter is ready (#2539)

This commit is contained in:
ocavue 2024-01-02 00:46:37 +08:00 committed by GitHub
parent e43993770d
commit 77588c1890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 41 deletions

View file

@ -7,11 +7,13 @@ 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)
const { highlighter, promise } = useHighlighter(lang as BuiltinLanguage)
// If the language is not loaded, we return an empty set of decorations
// 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 []
return promise ?? []
if (!parser)
parser = createParser(highlighter)