12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import { MDXProvider } from '@mdx-js/react';
- import { Highlight, themes, defaultProps } from 'prism-react-renderer';
- import CodePen from './src/components/CodePen';
- import Editor from './src/components/Editor';
- import {
- Heading1,
- Heading2,
- Heading3,
- Heading4,
- Heading5,
- Heading6,
- } from './src/components/Heading';
- const components = {
- CodePen,
- Editor,
- More: () => <div style={{ display: 'none' }}>{/* more */}</div>,
- h1: Heading1,
- h2: Heading2,
- h3: Heading3,
- h4: Heading4,
- h5: Heading5,
- h6: Heading6,
- pre: ({ children }) => {
- const className = children.props.className || '';
- const matches = className.match(/language-(?<lang>.*)/);
- return (
- <Highlight
- {...defaultProps}
- code={children.props.children}
- language={
- matches && matches.groups && matches.groups.lang
- ? matches.groups.lang
- : ''
- }
- >
- {({ className, style, tokens, getLineProps, getTokenProps }) => (
- <pre className={className} style={style}>
- <code>
- {tokens.map((line, i) =>
- i === tokens.length - 1 &&
- line[0].empty &&
- line.length === 1 ? null : (
- <div {...getLineProps({ line, key: i })}>
- {line.map((token, key) => (
- <span {...getTokenProps({ token, key })} />
- ))}
- </div>
- ),
- )}
- </code>
- </pre>
- )}
- </Highlight>
- );
- },
- };
- export const wrapRootElement = ({ element }) => (
- <MDXProvider components={components}>{element}</MDXProvider>
- );
|