import Link from 'next/link' import Image from 'next/image' import { MDXRemote } from 'next-mdx-remote/rsc' // import { highlight } from 'sugar-high' import React from 'react' function Table({ data }) { let headers = data.headers.map((header, index) => ( {header} )) let rows = data.rows.map((row, index) => ( {row.map((cell, cellIndex) => ( {cell} ))} )) return ( {headers}{rows}
) } function CustomLink(props) { let href = props.href if (href.startsWith('/')) { return ( {props.children} ) } if (href.startsWith('#')) { return } return } function RoundedImage(props) { return {props.alt} } // function Code({ children, ...props }) { // let codeHTML = highlight(children) // return // } function slugify(str) { return str .toString() .toLowerCase() .trim() // Remove whitespace from both ends of a string .replace(/\s+/g, '-') // Replace spaces with - .replace(/&/g, '-and-') // Replace & with 'and' .replace(/[^\w\-]+/g, '') // Remove all non-word characters except for - .replace(/\-\-+/g, '-') // Replace multiple - with single - } function createHeading(level) { const Heading = ({ children }) => { let slug = slugify(children) return React.createElement( `h${level}`, { id: slug }, [ React.createElement('a', { href: `#${slug}`, key: `link-${slug}`, className: 'anchor', }), ], children ) } Heading.displayName = `Heading${level}` return Heading } let components = { h1: createHeading(1), h2: createHeading(2), h3: createHeading(3), h4: createHeading(4), h5: createHeading(5), h6: createHeading(6), Image: RoundedImage, a: CustomLink, // code: Code, Table, } export function CustomMDX(props) { return ( ) }