diff --git a/mdx-components.jsx b/mdx-components.jsx index 3d9edb6c..0eaa56fe 100644 --- a/mdx-components.jsx +++ b/mdx-components.jsx @@ -1,21 +1,28 @@ +import slugify from "@sindresorhus/slugify"; import Image from "next/image"; import DocsLayout from "@/components/docs-layout"; import CustomLink from "@/components/link"; -// This file allows you to provide custom React components -// to be used in MDX files. You can import and use any -// React component you want, including inline styles, -// components from other libraries, and more. + +// Custom heading component with clickable anchor links +const Heading = ({ level, children, ...props }) => { + const Tag = `h${level}`; + // Ensure children are treated as a single string for slug generation + const textContent = Array.isArray(children) + ? children.join("") // Join array items if children is an array + : children?.toString() || ""; // Convert children to string or fallback to empty + const id = slugify(textContent); // Generate slug from heading text + + return ( + + + {children} + + + ); +}; export function useMDXComponents(components) { return { - // Allows customizing built-in components, e.g. to add styling. - // pre: ({children, ...props}) => { - // return
{children}
- // }, - // code: ({children, ...props}) => { - // console.log("code", props) - // return {children} - // }, img: ({ src }, ...props) => ( {props.alt} , wrapper: DocsLayout, + h1: (props) => , + h2: (props) => , + h3: (props) => , + h4: (props) => , + h5: (props) => , + h6: (props) => , ...components, }; }