import { useState, useCallback, type HTMLAttributes } from 'react'; import { Check, Copy } from 'lucide-react'; /** * Custom
renderer for ReactMarkdown. * Wraps code blocks with a floating copy button. */ export function CodeBlock(props: HTMLAttributes) { const [copied, setCopied] = useState(false); const handleCopy = useCallback(() => { // Extract text from the nested element const code = (props.children as React.ReactElement<{ children?: string }> | undefined)?.props?.children; if (typeof code === 'string') { navigator.clipboard.writeText(code).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); } }, [props.children]); return (); }