import { Children, isValidElement } from "react"; import ReactMarkdown from "react-markdown"; import rehypeKatex from "rehype-katex"; import remarkGfm from "remark-gfm"; import remarkMath from "remark-math"; import { CodeBlock } from "@/components/CodeBlock"; import { cn } from "@/lib/utils"; import "katex/dist/katex.min.css"; interface MarkdownTextRendererProps { children: string; className?: string; } /** * Heavy markdown stack (GFM, math, KaTeX, syntax highlighting) kept in a * separate chunk so the app shell can paint sooner on refresh. */ export default function MarkdownTextRenderer({ children, className, }: MarkdownTextRendererProps) { return (
{kids}
);
}
return (
{kids}
);
},
pre({ children: markdownChildren }) {
const kids = Children.toArray(markdownChildren);
const lone = kids.length === 1 ? kids[0] : null;
/** Highlighted fences render ``CodeBlock`` (block shell); skip invalid ````. */ if (lone != null && isValidElement(lone) && lone.type === CodeBlock) { return <>{markdownChildren}>; } return (); }{markdownChildren}); }, a({ href, children: markdownChildren, ...props }) { return ( {markdownChildren} ); }, }} > {children}