'use client' import type { RawContentMatch } from '@admin/utils/editor/raw-content-match' const mathBlockEnvironmentNames = new Set([ 'align', 'align*', 'aligned', 'alignedat', 'alignedat*', 'array', 'bmatrix', 'cases', 'equation', 'equation*', 'gather', 'gather*', 'gathered', 'matrix', 'multline', 'multline*', 'pmatrix', 'smallmatrix', 'split', 'vmatrix' ]) export function matchBlockMath(src: string): RawContentMatch | null { const bracketMatch = /^\\\[[\s\S]*?\\\][ \t]*(?:\n|$)/.exec(src) if (bracketMatch) { return { kind: 'math', raw: bracketMatch[0].trimEnd() } } const dollarMatch = /^\$\$[\s\S]*?\$\$[ \t]*(?:\n|$)/.exec(src) if (dollarMatch) { return { kind: 'math', raw: dollarMatch[0].trimEnd() } } const environmentMatch = /^\\begin\{([^}]+)\}[\s\S]*?\\end\{\1\}[ \t]*(?:\n|$)/.exec(src) if (environmentMatch && mathBlockEnvironmentNames.has(environmentMatch[1])) { return { kind: 'math', raw: environmentMatch[0].trimEnd() } } return null }