/** * 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}

) }, h2: ({ children, ...props }) => { const text = getTextContent(children) const id = slugify(text) return (

{children}

) }, h3: ({ children, ...props }) => { const text = getTextContent(children) const id = slugify(text) return (

{children}

) }, h4: ({ children, ...props }) => { const text = getTextContent(children) const id = slugify(text) return (

{children}

) }, // Paragraphs p: ({ children, ...props }) => (
{children}
), // Lists ul: ({ children, ...props }) => ( ), ol: ({ children, ...props }) => (
    {children}
), li: ({ children, ...props }) => (
  • {children}
  • ), // Links a: ({ href, children, ...props }) => ( {children} ), // Images img: ({ src, alt, width, height, ...props }) => { if (!src) return null return (
    {alt
    {alt && (
    {alt}
    )}
    ) }, // Code blocks pre: ({ children, ...props }) => (
          {children}
        
    ), code: ({ children, ...props }) => ( {children} ), // Blockquote blockquote: ({ children, ...props }) => (
    {children}
    ), // Horizontal rule hr: (props) => (
    ), // Table table: ({ children, ...props }) => (
    {children}
    ), th: ({ children, ...props }) => ( {children} ), td: ({ children, ...props }) => ( {children} ), // Strong/Bold strong: ({ children, ...props }) => ( {children} ), // Emphasis/Italic em: ({ children, ...props }) => ( {children} ), }