-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap-root-element.js
More file actions
22 lines (21 loc) · 805 Bytes
/
wrap-root-element.js
File metadata and controls
22 lines (21 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* eslint react/prop-types: 0 */
/* eslint react/display-name: 0 */
import React from 'react'
import { MDXProvider } from '@mdx-js/react'
import { preToCodeBlock } from 'mdx-utils'
import Code from './src/components/Code'
// components is its own object outside of render so that the references to
// components are stable
const components = {
pre: preProps => {
const props = preToCodeBlock(preProps)
// if there's a codeString and some props, we passed the test
if (props) {
return <Code {...props} />
}
// it's possible to have a pre without a code in it
return <pre {...preProps} />
},
wrapper: ({ children }) => <>{children}</>,
}
export const wrapRootElement = ({ element }) => <MDXProvider components={components}>{element}</MDXProvider>