import rehypePrism from '@mapbox/rehype-prism'; import clsx from 'clsx'; import { createElement, Fragment, memo } from 'react'; import rehypeReact from 'rehype-react'; import remarkGfm from 'remark-gfm'; import remarkParse from 'remark-parse'; import remarkRehype from 'remark-rehype'; import { GistsFile } from 'types'; import { unified } from 'unified'; import styles from './gists-code.module.css'; interface Props { file: GistsFile; showFileName?: boolean; } const GistsCode = ({ file, showFileName = false }: Props) => { const fileContent = showFileName ? file.content : file.content?.split('\n').slice(0, 20).join('\n'); const code = unified() .use(remarkParse) .use(remarkRehype) .use(remarkGfm) .use(rehypePrism, { ignoreMissing: true }) .use(rehypeReact, { createElement, Fragment, }) .processSync(`\`\`\`${file.language ?? ''}\n${fileContent}`).result; return ( <> {showFileName ? (