1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-05 08:29:57 +00:00
elk/composables/tiptap/shikiji-parser.ts

21 lines
563 B
TypeScript

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)
}