import Link from "next/link"; import React, { memo, useState } from "react"; import ReactMarkdown, { type Components } from "react-markdown"; import remarkGfm from "remark-gfm"; import { cn } from "@/lib/utils"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { tomorrow, oneLight } from "react-syntax-highlighter/dist/cjs/styles/prism"; import { Check, Copy } from "lucide-react"; import { useTheme } from "next-themes"; // Code Block component with copy button const CodeBlock = ({ className, children }: { className?: string; children: string }) => { const [copied, setCopied] = useState(false); const match = /language-(\w+)/.exec(className || ''); const language = match ? match[1] : ''; const { theme } = useTheme(); const handleCopy = () => { navigator.clipboard.writeText(children); setCopied(true); setTimeout(() => setCopied(false), 2000); }; // Select appropriate theme based on the app's current theme const codeStyle = theme === 'light' || theme === 'sunset' ? oneLight : tomorrow; return (
{children}), code: ({ children, className, ...props }: React.HTMLProps
{children}
);
}
// For code blocks, use our custom CodeBlock component
return {children}
), strong: ({ node, children, ...props }) => ( {children} ), em: ({ node, children, ...props }) => ( {children} ), blockquote: ({ node, children, ...props }) => ({children}), a: ({ node, children, ...props }) => ( // @ts-expect-error error {children} ), h1: ({ node, children, ...props }) => (