/** * Custom MDX Components * * Styled components for rendering MDX content */ import Image from 'next/image' import Link from 'next/link' import type { MDXComponents } from 'mdx/types' /** * Generate slug from heading text for anchor links */ function slugify(text: string): string { return text .toString() .toLowerCase() .trim() .replace(/\s+/g, '-') .replace(/[^\w\-]+/g, '') .replace(/\-\-+/g, '-') } /** * Extract text content from React children */ function getTextContent(children: React.ReactNode): string { if (typeof children === 'string') return children if (Array.isArray(children)) return children.map(getTextContent).join('') if (children && typeof children === 'object' && 'props' in children) { return getTextContent(children.props.children) } return '' } export const mdxComponents: MDXComponents = { // Headings with anchor links h1: ({ children, ...props }) => { const text = getTextContent(children) const id = slugify(text) return (
{children}
),
code: ({ children, ...props }) => (
{children}
),
// Blockquote
blockquote: ({ children, ...props }) => (
{children}), // Horizontal rule hr: (props) => (