diff --git a/README.md b/README.md index 410e43e..b9b11d5 100644 --- a/README.md +++ b/README.md @@ -175,11 +175,11 @@ export async function getStaticProps() { Custom components from MDXProvider -If you want to make components available to any `` being rendered in your application, you can use [``](https://mdxjs.com/docs/using-mdx/#mdx-provider) from `@mdx-js/react`. +If you want to make components available to any `` being rendered in your application, you can use [``](https://mdxjs.com/docs/using-mdx/#mdx-provider) directly from `next-mdx-remote`. ```jsx // pages/_app.jsx -import { MDXProvider } from '@mdx-js/react' +import { MDXProvider } from 'next-mdx-remote' import Test from '../components/test' @@ -305,7 +305,7 @@ This library exposes a function and a component, `serialize` and `` mdxOptions: { remarkPlugins: [], rehypePlugins: [], - format: 'mdx' + format: 'mdx', }, // Indicates whether or not to parse the frontmatter from the mdx source parseFrontmatter: false, @@ -407,13 +407,12 @@ export default function ExamplePage({ mdxSource }: Props) { ) } -export const getStaticProps: GetStaticProps<{mdxSource: MDXRemoteSerializeResult}> = - async () => { - const mdxSource = await serialize( - 'some *mdx* content: ' - ) - return { props: { mdxSource } } - } +export const getStaticProps: GetStaticProps<{ + mdxSource: MDXRemoteSerializeResult +}> = async () => { + const mdxSource = await serialize('some *mdx* content: ') + return { props: { mdxSource } } +} ``` ## Migrating from v2 to v3 diff --git a/__tests__/serialize.test.tsx b/__tests__/serialize.test.tsx index 177d50d..a5b071f 100644 --- a/__tests__/serialize.test.tsx +++ b/__tests__/serialize.test.tsx @@ -3,7 +3,7 @@ import ReactDOMServer from 'react-dom/server' import { paragraphCustomAlerts } from '@hashicorp/remark-plugins' import * as MDX from '@mdx-js/react' -import { MDXRemote } from '../src/index' +import { MDXRemote, MDXProvider } from '../src/index' import { serialize } from '../src/serialize' import { renderStatic } from '../.jest/utils' @@ -74,13 +74,13 @@ describe('serialize', () => { const mdxSource = await serialize('') const result = ReactDOMServer.renderToStaticMarkup( -

Hello world

, }} > -
+
) expect(result).toMatchInlineSnapshot(`"

Hello world

"`) diff --git a/src/index.tsx b/src/index.tsx index 5e5c728..75cc04e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -40,6 +40,8 @@ export type MDXRemoteProps = MDXRemoteSerializeResult & { export { MDXRemoteSerializeResult } +export const MDXProvider = mdx.MDXProvider + /** * Renders compiled source from next-mdx-remote/serialize. */ @@ -101,9 +103,9 @@ export function MDXRemote({ // wrapping the content with MDXProvider will allow us to customize the standard // markdown components (such as "h1" or "a") with the "components" object const content = ( - + - +
) // If lazy = true, we need to render a wrapping div to preserve the same markup structure that was SSR'd