"use client"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; import rehypeKatex from "rehype-katex"; import rehypePrism from "rehype-prism-plus"; import type { Components } from "react-markdown"; import { cn } from "@/lib/utils"; interface MarkdownProps { children: string; className?: string; } export function Markdown({ children, className }: MarkdownProps) { const normalizeMathDelimiters = (src: string) => { const segments = src.split(/(```[\s\S]*?```)/g); return segments .map((seg) => (seg.startsWith("```") ? seg : seg.replace(/\$\$\$/g, "$$"))) .join(""); }; const content = normalizeMathDelimiters(children); const components: Components = { pre: ({ children, ...props }) => (
{children}
),
code: ({ children, className: codeClassName, ...props }) => {
const isInline = !codeClassName;
if (isInline) {
return (
{children}
);
}
return (
{children}
);
},
p: ({ children }) => {children}
, ul: ({ children }) =>{children}, a: ({ children, href }) => ( {children} ), strong: ({ children }) => {children}, em: ({ children }) => {children}, hr: () =>