import { MDXProvider } from '@mdx-js/react'; import * as ReactDOM from 'react-dom/server'; import Link from 'next/link'; import Highlight, { defaultProps } from 'prism-react-renderer'; import stripHtml from 'string-strip-html'; import slugify from '@sindresorhus/slugify'; const THEME = { plain: { color: '#000', backgroundColor: 'transparent', }, styles: [ { types: ['keyword'], style: { color: '#ff0078', fontWeight: 'bold', }, }, { types: ['comment'], style: { color: '#999', fontStyle: 'italic', }, }, { types: ['string', 'url', 'attr-value'], style: { color: '#028265', }, }, { types: ['builtin', 'char', 'constant', 'language-javascript'], style: { color: '#000', }, }, { types: ['attr-name'], style: { color: '#d9931e', fontStyle: 'normal', }, }, { types: ['punctuation', 'operator'], style: { color: '#333', }, }, { types: ['number', 'function', 'tag'], style: { color: '#0076ff', }, }, { types: ['boolean', 'regex'], style: { color: '#d9931e', }, }, ], }; // Anchor links const HeaderLink = ({ tag: Tag, children, ...props }) => { const slug = slugify(ReactDOM.renderToString(children) || ''); return ( {children} # ); }; const H2 = ({ children, ...props }) => { return ( {children} ); }; const H3 = ({ children, ...props }) => { return ( {children} ); }; const H4 = ({ children, ...props }) => { return ( {children} ); }; const H5 = ({ children, ...props }) => { return ( {children} ); }; const H6 = ({ children, ...props }) => { return ( {children} ); }; const A = ({ children, ...props }) => { const isExternal = props.href?.startsWith('https://'); if (isExternal) { return ( {children} ); } return ( {children} ); }; const Code = ({ children, className, highlight, ...props }) => { if (!className) return {children}; const highlightedLines = highlight ? highlight.split(',').map(Number) : []; // https://mdxjs.com/guides/syntax-highlighting#all-together const language = className.replace(/language-/, ''); return ( {({ className, style, tokens, getLineProps, getTokenProps }) => ( {tokens.map((line, i) => (
{line.map((token, key) => ( ))}
))}
)}
); }; const components = { h2: H2, h3: H3, h4: H4, h5: H5, h6: H6, a: A, code: Code, }; export default ({ children }) => { return {children}; };