"use client"; import React, { useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import rehypeSlug from "rehype-slug"; function CodeBlock({ children, className, ...props }: React.HTMLAttributes) { const [copied, setCopied] = useState(false); const textContent = String(children).replace(/\n$/, ""); const match = /language-(\w+)/.exec(className || ""); const language = match ? match[1] : ""; // If inline code if (!className && typeof children === "string" && !children.includes("\n")) { return ( {children} ); } function handleCopy() { navigator.clipboard.writeText(textContent); setCopied(true); setTimeout(() => setCopied(false), 2000); } return (
{/* Code block header bar */}
{language || "text"}
        
          {children}
        
      
); } export default function Markdown({ source }: { source: string }) { return (
<>{children}, table: ({ node, ...props }) => (
), blockquote: ({ children }) => { return (
{children}
); }, }} > {source} ); }