mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-24 02:06:12 +03:00
320ddc0e28
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
22 lines
689 B
TypeScript
22 lines
689 B
TypeScript
import type { BuiltinLanguage } from 'shiki'
|
|
import { createParser, type Parser } from 'prosemirror-highlight/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)
|
|
}
|