import Link from "next/link"; import ReactMarkdown from "react-markdown"; import rehypeHighlight from "rehype-highlight"; import rehypeRaw from "rehype-raw"; import rehypeSlug from "rehype-slug"; import remarkGfm from "remark-gfm"; import WikiPage from "../../interfaces/WikiPage"; interface RenderMarkdownProps { children: string; page: WikiPage; } export default function RenderMarkdown({ children, page, }: RenderMarkdownProps) { return ( { // if the link is internal, reformat it; if it ends with a slash, do not apply this let href = props.href as string; if (!href.endsWith("/") && !href.startsWith("http")) { if (href.startsWith("/wiki/")) { href = `/wiki/${page.language}${href.slice(5)}`; } else { // if single relative href = `/wiki/${page.language}/${page.path}/${href}`; } } return ( {props.children ? props.children[0] : href} ); }, img: ({ node, ...props }) => { // if image is internal (relative), prefix it with the current page's path let src = props.src as string; if (!src.startsWith("http") && !src.startsWith("/")) { src = `/img/wiki/${page.path}/${src}`; } return (
{props.alt

{props.title as string}

); }, }} > {children}
); }