import { Children } from "react"
import { ExternalLinkIcon } from "lucide-react"
import type { MDXComponents } from "mdx/types"
import { cn } from "@/lib/utils"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { CodeSnippet } from "@/components/code-snippet"
import { ComponentPreview } from "@/components/component-preview"
import { ComponentSource } from "@/components/component-source"
import { ExplanationDemo } from "@/components/explanation-demo"
import { InstallTabs } from "@/components/install-tabs"
import "katex/dist/katex.min.css"
import Link from "next/link"
import { BlockMath, InlineMath } from "react-katex"
export function mdxComponents(components?: MDXComponents): MDXComponents {
return {
h1: ({ className, children, ...props }: React.ComponentProps<"h1">) => (
{children}
),
h2: ({ className, children, ...props }: React.ComponentProps<"h2">) => (
<>
{children}
>
),
h3: ({ className, children, ...props }: React.ComponentProps<"h3">) => (
{children}
),
h4: ({ className, children, ...props }: React.ComponentProps<"h4">) => (
{children}
),
a: ({
className,
children,
...props
}: React.HTMLAttributes) => (
{children}
),
Link: ({
className,
href,
children,
...props
}: React.ComponentProps) => (
{children}
),
p: ({
className,
...props
}: React.HTMLAttributes) => (
),
strong: ({ className, ...props }: React.HTMLAttributes) => (
),
em: ({ className, ...props }: React.HTMLAttributes) => (
),
ul: ({ className, ...props }: React.HTMLAttributes) => (
),
ol: ({ className, ...props }: React.HTMLAttributes) => (
),
li: ({ className, ...props }: React.HTMLAttributes) => (
ul]:marker:text-[10px] [&>ol]:marker:text-base text-base md:text-lg first:mt-2 last:pb-4",
className
)}
{...props}
/>
),
math: ({ children }) => {children},
inlineMath: ({ children }) => {children},
blockquote: ({
className,
...props
}: React.HTMLAttributes) => (
),
img: ({
className,
alt,
...props
}: React.ImgHTMLAttributes) => (
//@ts-expect-error img src expects a Blob or string
()
),
hr: ({ ...props }: React.HTMLAttributes) => (
),
code: ({ className, ...props }: React.HTMLAttributes) => (
),
InstallTabs,
CodeSnippet: ({
className,
title,
children,
...props
}: React.HTMLAttributes & {
title?: string
}) => {
// Extract code content and language from children
const preElement = Children.toArray(children)[0] as React.ReactElement
//@ts-ignore
const codeElement = preElement?.props?.children as React.ReactElement<{
className?: string
children?: string
}>
if (!codeElement) return null
const code = codeElement.props.children || ""
const language =
codeElement.props.className?.replace("language-", "") || "typescript"
return (
)
},
ComponentPreview,
ComponentSource,
ExplanationDemo,
Table: ({ className, ...props }: React.ComponentProps) => (
),
TableHeader: ({
className,
...props
}: React.ComponentProps) => (
),
TableBody: ({
className,
...props
}: React.ComponentProps) => (
),
TableRow: ({
className,
...props
}: React.ComponentProps) => (
),
TableCell: ({
className,
...props
}: React.ComponentProps) => (
),
TableHead: ({
className,
...props
}: React.ComponentProps) => (
),
Tabs: ({ className, ...props }: React.ComponentProps) => (
),
TabsList: ({
className,
...props
}: React.ComponentProps) => (
),
TabsTrigger: ({
className,
...props
}: React.ComponentProps) => (
),
TabsContent: ({
className,
...props
}: React.ComponentProps) => (
),
...components,
};
}