fix: add button override to handle transformerCopyButton onclick string

This commit is contained in:
2026-06-01 23:17:51 -05:00
parent 4717dde7a2
commit fe4261f58f

View File

@@ -105,5 +105,28 @@ export function getMDXComponents(components: MDXComponents): MDXComponents {
// Collapsible sections
details: (props) => <details className="my-4 rounded-lg border border-border p-4" {...props} />,
summary: (props) => <summary className="cursor-pointer font-semibold" {...props} />,
// Buttons (handle onclick string from transformerCopyButton)
button: ({ children, onClick, ...props }: { children?: React.ReactNode; onClick?: string | (() => void); className?: string } & Record<string, unknown>) => {
if (typeof onClick === 'string') {
const className = (props.className as string) ?? '';
return (
<button
dangerouslySetInnerHTML={{
__html: `<button${className ? ` class="${className.replace(/"/g, '&quot;')}"` : ''} onclick="${onClick}">${(children as string) ?? ''}</button>`
}}
suppressHydrationWarning
/>
);
}
return (
<button
{...props}
onClick={typeof onClick === 'function' ? onClick : undefined}
>
{children}
</button>
);
},
}
}