fix: guard ai markdown highlighting on legacy webkit

This commit is contained in:
lucaronin
2026-05-08 14:59:44 +02:00
parent 81ba8f80d5
commit 5a75548652
5 changed files with 96 additions and 15 deletions

View File

@@ -1,21 +1,12 @@
import { codeBlockOptions } from '@blocknote/code-block'
import type { CodeBlockOptions } from '@blocknote/core'
import { supportsModernRegexFeatures } from '../utils/regexCapabilities'
const LIGHT_CODE_THEME = 'github-light'
const DARK_CODE_THEME = 'github-dark'
type TolariaCodeHighlighter = Awaited<ReturnType<NonNullable<typeof codeBlockOptions.createHighlighter>>>
function supportsShikiPrecompiledRegexFlags() {
try {
new RegExp('', 'd')
new RegExp('[[]]', 'v')
return true
} catch {
return false
}
}
function currentCodeBlockTheme() {
if (typeof document === 'undefined') return LIGHT_CODE_THEME
@@ -44,7 +35,7 @@ export function createTolariaCodeBlockOptions(): Partial<CodeBlockOptions> {
defaultLanguage: 'text',
}
if (supportsShikiPrecompiledRegexFlags()) return options
if (supportsModernRegexFeatures()) return options
delete options.createHighlighter
return options