fix: disable unsafe shiki highlighting on old webkit
This commit is contained in:
24
src/components/codeBlockOptions.ts
Normal file
24
src/components/codeBlockOptions.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { codeBlockOptions } from '@blocknote/code-block'
|
||||
import type { CodeBlockOptions } from '@blocknote/core'
|
||||
|
||||
function supportsShikiPrecompiledRegexFlags() {
|
||||
try {
|
||||
new RegExp('', 'd')
|
||||
new RegExp('[[]]', 'v')
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function createTolariaCodeBlockOptions(): Partial<CodeBlockOptions> {
|
||||
const options: Partial<CodeBlockOptions> = {
|
||||
...codeBlockOptions,
|
||||
defaultLanguage: 'text',
|
||||
}
|
||||
|
||||
if (supportsShikiPrecompiledRegexFlags()) return options
|
||||
|
||||
delete options.createHighlighter
|
||||
return options
|
||||
}
|
||||
Reference in New Issue
Block a user