import { cn } from "@midday/ui/cn"; import Image from "next/image"; import Link from "next/link"; import { MDXRemote } from "next-mdx-remote/rsc"; import type { AnchorHTMLAttributes, ComponentProps, HTMLAttributes, ReactNode, } from "react"; import remarkGfm from "remark-gfm"; import { highlight } from "sugar-high"; function slugify(str: string): string { return str .toString() .toLowerCase() .trim() .replace(/\s+/g, "-") .replace(/&/g, "-and-") .replace(/[^\w-]+/g, "") .replace(/--+/g, "-"); } function createHeading(level: number) { const Heading = ({ children }: { children: ReactNode }) => { const slug = slugify(children as string); const Tag = `h${level}` as keyof JSX.IntrinsicElements; return ( # {children} ); }; Heading.displayName = `Heading${level}`; return Heading; } interface CustomLinkProps extends AnchorHTMLAttributes { href: string; } function CustomLink({ href, children, ...props }: CustomLinkProps) { const isInternal = href.startsWith("/") || href.startsWith("#"); const isAnchor = href.startsWith("#"); if (isAnchor) { return ( {children} ); } if (isInternal) { return ( {children} ); } return ( {children} ); } interface CodeProps { children: string; className?: string; } function InlineCode({ children, className, ...props }: CodeProps) { // Check if this is a code block (has language class) or inline code if (className?.includes("language-")) { const codeHTML = highlight(children); return ( ); } return ( {children} ); } function Pre({ children, ...props }: HTMLAttributes) { return (
      {children}
    
); } interface ImageProps extends ComponentProps { alt: string; } function DocImage(props: ImageProps) { return ( ); } function Blockquote({ children }: { children: ReactNode }) { return (
{children}
); } function Hr() { return
; } function OrderedList({ children }: { children: ReactNode }) { return
    {children}
; } function UnorderedList({ children }: { children: ReactNode }) { return
    {children}
; } function ListItem({ children }: { children: ReactNode }) { return
  • {children}
  • ; } function Paragraph({ children }: { children: ReactNode }) { return

    {children}

    ; } function Strong({ children }: { children: ReactNode }) { return {children}; } interface TableProps { children: ReactNode; } function Table({ children }: TableProps) { return (
    {children}
    ); } function TableHead({ children }: { children: ReactNode }) { return ( {children} ); } function TableBody({ children }: { children: ReactNode }) { return {children}; } function TableRow({ children }: { children: ReactNode }) { return ( {children} ); } function TableHeader({ children }: { children: ReactNode }) { return ( {children} ); } function TableCell({ children }: { children: ReactNode }) { return {children}; } const components = { h1: createHeading(1), h2: createHeading(2), h3: createHeading(3), h4: createHeading(4), h5: createHeading(5), h6: createHeading(6), a: CustomLink, code: InlineCode, pre: Pre, Image: DocImage, img: DocImage, blockquote: Blockquote, hr: Hr, ol: OrderedList, ul: UnorderedList, li: ListItem, p: Paragraph, strong: Strong, table: Table, thead: TableHead, tbody: TableBody, tr: TableRow, th: TableHeader, td: TableCell, }; interface DocsMDXProps { source: string; } export function DocsMDX({ source }: DocsMDXProps) { return (
    h1]:text-3xl [&>h1]:font-serif [&>h1]:text-foreground [&>h1]:tracking-tight [&>h1]:mt-0 [&>h1]:mb-6", "[&>h2]:text-xl [&>h2]:font-serif [&>h2]:text-foreground [&>h2]:tracking-tight [&>h2]:mt-12 [&>h2]:mb-4 [&>h2]:pt-6 [&>h2]:border-t [&>h2]:border-border first:[&>h2]:mt-0 first:[&>h2]:pt-0 first:[&>h2]:border-t-0", "[&>h3]:text-lg [&>h3]:font-serif [&>h3]:text-foreground [&>h3]:tracking-tight [&>h3]:mt-8 [&>h3]:mb-3", "[&>h4]:text-base [&>h4]:font-medium [&>h4]:text-foreground [&>h4]:mt-6 [&>h4]:mb-2", // Links "[&_a]:text-foreground [&_a]:underline [&_a]:underline-offset-4 [&_a]:decoration-border hover:[&_a]:decoration-foreground [&_a]:transition-colors", // Code "[&_code]:bg-[#f5f5f5] [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:text-sm [&_code]:text-foreground [&_code]:rounded-none dark:[&_code]:bg-secondary", "[&_pre]:bg-[#fafafa] [&_pre]:border [&_pre]:border-border [&_pre]:p-4 [&_pre]:my-6 [&_pre]:rounded-none dark:[&_pre]:bg-[#0c0c0c]", "[&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:rounded-none", )} >
    ); }