import { useMemo } from 'react'; import type { Components } from 'react-markdown'; import ReactMarkdown from 'react-markdown'; import rehypeKatex from 'rehype-katex'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import MarkdownCodeBlock from './MarkdownCodeBlock'; type MarkdownPreviewProps = { content: string; }; const markdownPreviewComponents: Components = { code: MarkdownCodeBlock, // MarkdownCodeBlock renders its own highlighted
; passthrough prevents a
// second Typography-styled shell from framing it.
pre: ({ children }) => <>{children}>,
blockquote: ({ children }) => (
{children}
),
a: ({ href, children }) => (
{children}
),
table: ({ children }) => (
{children}
),
thead: ({ children }) => {children},
th: ({ children }) => (
{children}
),
td: ({ children }) => (
{children}
),
};
export default function MarkdownPreview({ content }: MarkdownPreviewProps) {
const remarkPlugins = useMemo(() => [remarkGfm, remarkMath], []);
const rehypePlugins = useMemo(() => [rehypeKatex], []);
return (
{content}
);
}