import { Box, PropsOf, Text } from "@chakra-ui/react"; import { Language } from "prism-react-renderer"; import type { FunctionComponent } from "react"; import { Code } from "./Code"; import { ExternalLink } from "../ExternalLink"; import { NavLink } from "../NavLink"; type AnchorComponent = FunctionComponent< PropsOf | PropsOf >; export const A: AnchorComponent = ({ children, href, ...linkProps }) => { const sharedProps = { color: "link", // If we are rendering an img within the link (specifically stability banners), // do not display the external link Icon sx: { "> img + svg": { display: "none" } }, }; try { if (href && href.startsWith("http")) { // new URL() throws if the url is invalid const hostname = new URL(href).hostname; if (hostname !== window.location.hostname) { return ( {children} ); } } } catch {} return ( {children} ); }; export const Blockquote: FunctionComponent = ({ children }) => ( {children} ); export const Em: FunctionComponent = ({ children }) => ( {children} ); export const P: FunctionComponent = ({ children }) => ( {children} ); export const Pre: FunctionComponent<{ lang?: Language }> = ({ children, lang, }) => { if (lang) { return {children}; } return {children}; }; export const Sup: FunctionComponent = ({ children }) => { let color: string | undefined = undefined; let text = ""; if (Array.isArray(children)) { const [first] = children; if (typeof first === "string") { text = first; } } if (text === "Required") { color = "orange.700"; } else if (text === "Optional") { color = "green.700"; } return ( {children} ); };