'use client' import { useMemo } from 'react' import katex from 'katex' import 'katex/dist/katex.min.css' import { cn } from '@/lib/utils' /** Render node/callout label: plain lines + inline $KaTeX$. */ export function DemoRichLabel({ text, className, lit, }: { text: string className?: string lit?: boolean }) { const lines = useMemo(() => { return text.split(/\\n|\n/).map((line) => { const parts: Array<{ type: 'text' | 'math'; value: string }> = [] const re = /\$([^$]+)\$/g let last = 0 let m: RegExpExecArray | null while ((m = re.exec(line)) !== null) { if (m.index > last) { parts.push({ type: 'text', value: line.slice(last, m.index) }) } parts.push({ type: 'math', value: m[1] || '' }) last = m.index + m[0].length } if (last < line.length) parts.push({ type: 'text', value: line.slice(last) }) if (parts.length === 0) parts.push({ type: 'text', value: line }) return parts }) }, [text]) return (