'use client' import { useEffect, useRef, type ReactNode } from 'react' import DOMPurify from 'dompurify' import { MarkdownContent } from '@/components/markdown-content' import 'katex/dist/katex.min.css' import type { Note } from '@/lib/types' interface NotePeekContentProps { note: Note className?: string children?: ReactNode } export function NotePeekContent({ note, className, children }: NotePeekContentProps) { const htmlRef = useRef(null) useEffect(() => { if (!htmlRef.current || note.isMarkdown) return let cancelled = false void (async () => { const katex = (await import('katex')).default if (cancelled || !htmlRef.current) return htmlRef.current.querySelectorAll('.math-equation-block[data-latex], .inline-math[data-latex]').forEach(el => { const latex = el.getAttribute('data-latex') || '' const isDisplay = el.classList.contains('math-equation-block') try { el.innerHTML = katex.renderToString(latex, { displayMode: isDisplay, throwOnError: false }) } catch {} }) })() return () => { cancelled = true } }, [note.id, note.content, note.isMarkdown]) if (children) return <>{children} if (note.isMarkdown) { return } return (
) }