refactor: migrate to nuxt compatibilityVersion: 4 (#3298)
This commit is contained in:
parent
46e4433e1c
commit
a3fbc056a9
342 changed files with 1200 additions and 2932 deletions
23
app/composables/tiptap/shiki-parser.ts
Normal file
23
app/composables/tiptap/shiki-parser.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import type { Parser } from 'prosemirror-highlight/shiki'
|
||||
import type { BuiltinLanguage } from 'shiki'
|
||||
import { createParser } 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue