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 (
{language || 'plain text'}
{children}
); }; const components: Partial = { pre: ({ children, ...props }) => (
      {children}
    
), code: ({ children, className, ...props }: React.HTMLProps & { className?: string }) => { const match = /language-(\w+)/.exec(className || ''); const isInline = !match && !className; if (isInline) { return ( {children} ); } // For code blocks, use our custom CodeBlock component return {String(children).trim()}; }, ol: ({ node, children, ...props }) => (
    {children}
), ul: ({ node, children, ...props }) => ( ), li: ({ node, children, ...props }) => (
  • {children}
  • ), p: ({ node, children, ...props }) => (

    {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 }) => (

    {children}

    ), h2: ({ node, children, ...props }) => (

    {children}

    ), h3: ({ node, children, ...props }) => (

    {children}

    ), h4: ({ node, children, ...props }) => (

    {children}

    ), h5: ({ node, children, ...props }) => (
    {children}
    ), h6: ({ node, children, ...props }) => (
    {children}
    ), table: ({ node, children, ...props }) => (
    {children}
    ), thead: ({ node, children, ...props }) => ( {children} ), tbody: ({ node, children, ...props }) => ( {children} ), tr: ({ node, children, ...props }) => ( {children} ), th: ({ node, children, ...props }) => ( {children} ), td: ({ node, children, ...props }) => ( {children} ), hr: ({ node, ...props }) => (
    ), }; const remarkPlugins = [remarkGfm]; const NonMemoizedMarkdown = ({ children }: { children: string }) => { return ( {children} ); }; export const Markdown = memo( NonMemoizedMarkdown, (prevProps, nextProps) => prevProps.children === nextProps.children, );