import dynamic from "next/dynamic"; import Link from "next/link"; import Image from "next/image"; import type { LinkProps } from "next/link"; import type { ImageProps } from "next/image"; // The following components are all passed into in [slug].tsx as replacements for vanilla HTML tags. type CustomLinkProps = LinkProps & { target?: string; rel?: string; className?: string; children?: unknown; }; const CustomLink = ({ href, target, rel, className, children }: CustomLinkProps) => ( {children} ); type CustomImgProps = ImageProps & { caption?: unknown; }; const CustomImg = (props: CustomImgProps) => ( // the required height and width are part of the props, so they get automatically passed here with {...props}
{/* eslint-disable-next-line jsx-a11y/alt-text */}
); const CustomCode = (props: any) => { if (props.className?.split(" ").includes("hljs")) { const CopyButton = dynamic(() => import("./clipboard/CopyButton")); // full multi-line code blocks with highlight.js and copy-to-clipboard button return (
{props.children}
); } else { // inline code in paragraphs, headings, etc. (not highlighted) return {props.children}; } }; // These are the actual tags referenced in mdx files: const mdxComponents = { a: CustomLink, img: CustomImg, code: CustomCode, }; export default mdxComponents;