{"name":"gatsby-plugin-mdx","version":"5.17.0-react19.0","keywords":["gatsby","gatsby-plugin","mdx","markdown","remark","rehype"],"license":"MIT","_id":"gatsby-plugin-mdx@5.17.0-react19.0","maintainers":[{"name":"pieh","email":"misiek.piechowiak@gmail.com"},{"name":"kathmbeck","email":"katherine.beck@netlify.com"},{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},{"name":"mlgualtieri-gatsby","email":"mike.gualtieri@netlify.com"},{"name":"biscarch","email":"chris@christopherbiscardi.com"}],"homepage":"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx#readme","bugs":{"url":"https://github.com/gatsbyjs/gatsby/issues"},"dist":{"shasum":"3b58dc18034fa6a9c1174d812d24de099bb8bc6a","tarball":"http://registry-npm.ywwl.com/gatsby-plugin-mdx/download/gatsby-plugin-mdx-5.17.0-react19.0.tgz","fileCount":37,"integrity":"sha512-NDcYKGH6MzrhPwKqmlV4eQcOb3VY+9E6YDiLcUrx4qbvIT46J0ZHqyoxLxHaheNeBkDnlT+LE1wzEFCNJ3uKDg==","signatures":[{"sig":"MEQCIBmN9sNDTDXCScMLT2PSGqaeM2FkKe03WML8gd8qq5OtAiB//G1OTq1k8vYsjDj4jqPiAlI5ksFzQwUwNv1RaVo7Kg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":157585,"size":35425,"noattachment":false,"key":"/gatsby-plugin-mdx/-/gatsby-plugin-mdx-5.17.0-react19.0.tgz"},"jest":{"testEnvironment":"node"},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"820c2e8cc6695c740c2f52d172b88bbd9e01a1b8","scripts":{"test":"jest","build":"babel src --out-dir dist/ --ignore \"**/__tests__\" --ignore \"**/__mocks__\" --extensions \".ts\"","clean":"del-cli dist/*","watch":"babel -w src --out-dir dist/ --ignore \"**/__tests__\" --extensions \".ts,.tsx\"","prepare":"cross-env NODE_ENV=production npm run clean && npm run build && npm run typegen","typegen":"tsc --emitDeclarationOnly --declaration --declarationDir dist/"},"_npmUser":{"name":"serhalp-netlify","email":"philippe.serhal@netlify.com"},"deprecated":"This React 19 prerelease version may be selected unexpectedly by npm when resolving version ranges. Please use the latest stable version, or use @next to install React 19 compatible prerelease version.","repository":{"url":"git+https://github.com/gatsbyjs/gatsby.git","type":"git","directory":"packages/gatsby-plugin-mdx"},"_npmVersion":"lerna/3.22.1/node@v22.19.0+arm64 (darwin)","description":"MDX integration for Gatsby","directories":{},"_nodeVersion":"22.19.0","dependencies":{"acorn":"^8.8.2","vfile":"^5.3.7","astring":"^1.8.5","unified":"^10.1.2","fs-extra":"^11.2.0","acorn-jsx":"^5.3.2","deepmerge":"^4.3.1","@mdx-js/mdx":"^2.3.0","gray-matter":"^4.0.3","mdast-util-mdx":"^2.0.1","mdast-util-toc":"^6.1.1","unist-util-visit":"^4.1.2","gatsby-core-utils":"^4.16.0-next.0","mdast-util-to-hast":"^10.2.0","gatsby-plugin-utils":"^4.16.0-next.0","remark-unwrap-images":"^3.0.1","estree-util-build-jsx":"^2.2.2","mdast-util-to-markdown":"^1.5.0","rehype-infer-description-meta":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"del-cli":"^5.0.0","webpack":"~5.98.0","cross-env":"^7.0.3","@babel/cli":"^7.20.7","typescript":"^5.1.6","@babel/core":"^7.20.12","opentracing":"^0.14.7","@types/mdast":"^3.0.11","@types/unist":"^2.0.6","@types/estree":"^1.0.1","babel-preset-gatsby-package":"^3.16.0-next.0"},"peerDependencies":{"react":"^18.0.0 || ^19.0.0 || ^0.0.0","gatsby":"^5.0.0-next","react-dom":"^18.0.0 || ^19.0.0 || ^0.0.0","@mdx-js/react":"^2.0.0","gatsby-source-filesystem":"^5.0.0-next"},"_npmOperationalInternal":{"tmp":"tmp/gatsby-plugin-mdx_5.17.0-react19.0_1764019191300_0.7691675078650304","host":"s3://npm-registry-packages-npm-production"},"readme":"# gatsby-plugin-mdx\n\n`gatsby-plugin-mdx` is the official integration for using [MDX](https://mdxjs.com) with [Gatsby](https://www.gatsbyjs.com).\n\nMDX is markdown for the component era. It lets you write JSX embedded inside markdown. It’s a great combination because it allows you to use markdown’s often terse syntax (such as `# heading`) for the little things and JSX for more advanced components.\n\n<details>\n<summary><strong>Table of contents</strong></summary>\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Configuration](#configuration)\n  - [Extensions](#extensions)\n  - [`gatsby-remark-*` plugins](#gatsby-remark--plugins)\n  - [mdxOptions](#mdxoptions)\n- [Imports](#imports)\n- [Layouts](#layouts)\n- [Programmatically create MDX pages](#programmatically-create-mdx-pages)\n- [GraphQL MDX Node structure](#graphql-mdx-node-structure)\n- [Extending the GraphQL MDX nodes](#extending-the-graphql-mdx-nodes)\n- [Components](#components)\n  - [MDXProvider](#mdxprovider)\n  - [Shortcodes](#shortcodes)\n- [Migrating from v3 to v4](#migrating-from-v3-to-v4)\n- [Why MDX?](#why-mdx)\n- [Related](#related)\n\n</details>\n\n## Installation\n\n```shell\nnpm install gatsby-plugin-mdx gatsby-source-filesystem @mdx-js/react\n```\n\n## Usage\n\n> This README assumes you're using `gatsby@5.3.0` or later. If you're using an older Gatsby version or don't want to use ESM for your Gatsby files, refer to [this older version of the README](https://www.npmjs.com/package/gatsby-plugin-mdx/v/5.8.0).\n\nAfter installing `gatsby-plugin-mdx` you can add it to your plugins list in your `gatsby-config`.\n\nWe highly **recommend** using [ES Modules (ESM)](https://www.gatsbyjs.com/docs/how-to/custom-configuration/es-modules/) syntax for your `gatsby-config` file as it'll enable you to use the latest packages from the `unified` ecosystem.\n\nYou'll also want to configure `gatsby-source-filesystem` to point at your `src/pages` directory.\n\n```js:title=gatsby-config.mjs\nimport { dirname } from \"path\"\nimport { fileURLToPath } from \"url\"\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst config = {\n  plugins: [\n    `gatsby-plugin-mdx`,\n    {\n      resolve: `gatsby-source-filesystem`,\n      options: {\n        name: `pages`,\n        path: `${__dirname}/src/pages`,\n      },\n    },\n  ],\n}\n\nexport default config\n```\n\nBy default, this configuration will allow you to automatically create pages with `.mdx` files in `src/pages`.\n\nIf you have MDX files in another location than `src/pages` you'll need to add another instance of `gatsby-source-filesystem` and configure the `path` to point at this folder. This is necessary for MDX files that you want to import into React components or for files you want to query via GraphQL.\n\n**Please Note:**\n\n- `gatsby-plugin-mdx` requires `gatsby-source-filesystem` to be present and configured to process local MDX files in order to generate the resulting Gatsby nodes (`gatsby-source-filesystem` needs to discover all MDX files in order to create MDX nodes and allow the processing for each of them).\n- MDX syntax differs from Markdown as it only supports [CommonMark](https://commonmark.org/) by default. Nonstandard markdown features like [GitHub flavored markdown (GFM)](https://mdxjs.com/guides/gfm/) can be enabled with plugins (see [`mdxOptions` instructions](#mdxoptions)). GFM includes features like tables or footnotes.\n- Certain features like HTML syntax doesn't work in MDX. Read the [\"What is MDX?\" guide](https://mdxjs.com/docs/what-is-mdx/#markdown) to learn more.\n\nTo automatically create pages from MDX files outside of `src/pages` you'll need to configure `gatsby-plugin-page-creator` and `gatsby-source-filesystem` to point to this folder of files.\n\n```js:title=gatsby-config.mjs\nimport { dirname } from \"path\"\nimport { fileURLToPath } from \"url\"\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nconst config = {\n  plugins: [\n    `gatsby-plugin-mdx`,\n    {\n      resolve: `gatsby-source-filesystem`,\n      options: {\n        name: `posts`,\n        path: `${__dirname}/src/posts`,\n      },\n    },\n    {\n      resolve: `gatsby-plugin-page-creator`,\n      options: {\n        path: `${__dirname}/src/posts`,\n      },\n    },\n  ],\n}\n\nexport default config\n```\n\nAlso check out the guide [Adding MDX Pages](https://www.gatsbyjs.com/docs/how-to/routing/mdx/) for more details.\n\n## Configuration\n\n`gatsby-plugin-mdx` exposes a configuration API that can be used similarly to any other Gatsby plugin. You can define MDX extensions, layouts, global scope, and more.\n\n| Key                                              | Default    | Description                                                         |\n| ------------------------------------------------ | ---------- | ------------------------------------------------------------------- |\n| [`extensions`](#extensions)                      | `[\".mdx\"]` | Configure the file extensions that `gatsby-plugin-mdx` will process |\n| [`gatsbyRemarkPlugins`](#gatsby-remark--plugins) | `[]`       | Use Gatsby-specific remark plugins                                  |\n| [`mdxOptions`](#mdxOptions)                      | `{}`       | Options directly passed to `compile()` of `@mdx-js/mdx`             |\n\n### Extensions\n\nBy default, only files with the `.mdx` file extension are treated as MDX when\nusing `gatsby-source-filesystem`. To use `.md` or other file extensions, you can\ndefine an array of file extensions in the `gatsby-plugin-mdx` section of your\n`gatsby-config.js`.\n\n```js:title=gatsby-config.mjs\nconst config = {\n  plugins: [\n    {\n      resolve: `gatsby-plugin-mdx`,\n      options: {\n        extensions: [`.mdx`, `.md`],\n      },\n    },\n  ],\n}\n\nexport default config\n```\n\n### `gatsby-remark-*` plugins\n\nThis config option is used for compatibility with a set of plugins many people [use with remark](https://www.gatsbyjs.com/plugins/?=gatsby-remark-) that require the Gatsby environment to function properly. In some cases, like [gatsby-remark-prismjs](https://www.gatsbyjs.com/plugins/gatsby-remark-prismjs/), it makes more sense to use a library like [prism-react-renderer](https://github.com/FormidableLabs/prism-react-renderer) to render codeblocks using a [React component](/api-reference/mdx-provider). In other cases, like [gatsby-remark-images](https://www.gatsbyjs.com/plugins/gatsby-remark-images/), the interaction with the Gatsby APIs is well deserved because the images can be optimized by Gatsby and you should continue using it.\n\nWhen using these `gatsby-remark-*` plugins, be sure to also install their required peer dependencies. You can find that information in their respective README.\n\n```js:title=gatsby-config.mjs\nconst config = {\n  plugins: [\n    {\n      resolve: `gatsby-plugin-mdx`,\n      options: {\n        gatsbyRemarkPlugins: [\n          {\n            resolve: `gatsby-remark-images`,\n            options: {\n              maxWidth: 590,\n            },\n          },\n        ],\n      },\n    },\n  ],\n}\n\nexport default config\n```\n\nUsing a string reference is also supported for `gatsbyRemarkPlugins`.\n\n```js\ngatsbyRemarkPlugins: [`gatsby-remark-images`]\n```\n\n### mdxOptions\n\nThese configuration options are directly passed into the MDX compiler.\n\nSee all available options in [the official documentation of `@mdx-js/mdx`](https://mdxjs.com/packages/mdx/#compilefile-options).\n\n```js:title=gatsby-config.mjs\nimport remarkGfm from \"remark-gfm\"\nimport remarkExternalLinks from \"remark-external-links\"\nimport rehypeSlug from \"rehype-slug\"\nimport rehypeAutolinkHeadings from \"rehype-autolink-headings\"\n\nconst config = {\n  plugins: [\n    {\n      resolve: `gatsby-plugin-mdx`,\n      options: {\n        mdxOptions: {\n          remarkPlugins: [\n            // Add GitHub Flavored Markdown (GFM) support\n            remarkGfm,\n            // To pass options, use a 2-element array with the\n            // configuration in an object in the second element\n            [remarkExternalLinks, { target: false }],\n          ],\n          rehypePlugins: [\n            // Generate heading ids for rehype-autolink-headings\n            rehypeSlug,\n            // To pass options, use a 2-element array with the\n            // configuration in an object in the second element\n            [rehypeAutolinkHeadings, { behavior: `wrap` }],\n          ],\n        },\n      },\n    },\n  ],\n}\n\nexport default config\n```\n\n**Please Note:** Most of the remark/rehype/unified ecosystem is published as ESM which means that you have to use [ES Modules (ESM) and Gatsby](https://www.gatsbyjs.com/docs/how-to/custom-configuration/es-modules/).\n\n## Imports\n\nWhen importing a React component into your MDX, you can import it using the `import` statement like in JavaScript.\n\n```mdx\nimport { SketchPicker } from \"react-color\"\n\n# Hello, world!\n\nHere's a color picker!\n\n<SketchPicker />\n```\n\n**Note:** You should restart `gatsby develop` to update imports in MDX files. Otherwise, you'll get a `ReferenceError` for new imports. You can use the [shortcodes](#shortcodes) approach if that is an issue for you.\n\n## Layouts\n\nYou can use regular [layout components](https://www.gatsbyjs.com/docs/how-to/routing/layout-components/) to apply layout to your sub pages.\n\nTo inject them, you have several options:\n\n1. Use the [`wrapPageElement` API](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/#wrapPageElement) including its [SSR counterpart](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#wrapPageElement).\n1. Add an `export default Layout` statement to your MDX file, see [MDX documentation on Layout](https://mdxjs.com/docs/using-mdx/#layout).\n1. When using the [`createPage` action](https://www.gatsbyjs.com/docs/reference/config-files/actions/#createPage) to programatically create pages, you should use the following URI pattern for your page component: `your-layout-component.js?__contentFilePath=absolute-path-to-your-mdx-file.mdx`. To learn more about this, head to the [programmatically creating pages](https://www.gatsbyjs.com/docs/how-to/routing/mdx#programmatically-creating-pages) guide.\n\n## Programmatically create MDX pages\n\nRead the MDX documentation on [programmatically creating pages](https://www.gatsbyjs.com/docs/how-to/routing/mdx#programmatically-creating-pages) to learn more.\n\n## GraphQL MDX Node structure\n\nIn your GraphQL schema, you will discover several additional data related to your MDX content. While your local [GraphiQL](http://localhost:8000/___graphql) will give you the most recent data, here are the most relevant properties of the `Mdx` entities:\n\n| Property                   | Description                                                                                                                                                                  |\n| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `frontmatter`              | Sub-entity with all frontmatter data. Regular Gatsby transformations apply, like you can format dates directly within the query.                                             |\n| `excerpt`                  | A pruned variant of your content. By default trimmed to 140 characters. Based on [rehype-infer-description-meta](https://github.com/rehypejs/rehype-infer-description-meta). |\n| `tableOfContents`          | Generates a recursive object structure to reflect a table of contents. Based on [mdast-util-toc](https://github.com/syntax-tree/mdast-util-toc).                             |\n| `body`                     | The raw MDX body (so the MDX file without frontmatter)                                                                                                                       |\n| `internal.contentFilePath` | The absolute path to the MDX file (useful for passing it to `?__contentFilePath` query param for layouts). Equivalent to the `absolutePath` on File nodes.                   |\n\n## Extending the GraphQL MDX nodes\n\nUse the [`createNodeField`](https://www.gatsbyjs.com/docs/reference/config-files/actions/#createNodeField) action to extend MDX nodes. All new items will be placed under the `fields` key. You can [alias your `fields`](https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#aliasing-fields) to have them at the root of the GraphQL node.\n\n### timeToRead\n\n1. Install `reading-time` into your project:\n   ```shell\n   npm install reading-time\n   ```\n1. In your `gatsby-node` add a new field:\n\n   ```js:title=gatsby-node.mjs\n   import readingTime from \"reading-time\"\n\n   export const onCreateNode = ({ node, actions }) => {\n     const { createNodeField } = actions\n     if (node.internal.type === `Mdx`) {\n       createNodeField({\n         node,\n         name: `timeToRead`,\n         value: readingTime(node.body)\n       })\n     }\n   }\n   ```\n\n1. You're now able to query the information on the MDX node:\n   ```graphql\n   query {\n     mdx {\n       fields {\n         timeToRead {\n           minutes\n           text\n           time\n           words\n         }\n       }\n     }\n   }\n   ```\n\n### wordCount\n\nSee [timeToRead](#timeToRead). It returns `timeToRead.words`.\n\n### slug\n\nThis largely comes down to your own preference and how you want to wire things up. This here is one of many possible solutions to this:\n\n1. Install `@sindresorhus/slugify` into your project:\n   ```shell\n   npm install @sindresorhus/slugify\n   ```\n1. In your `gatsby-node` add a new field:\n\n   ```js:title=gatsby-node.mjs\n   import slugify from \"@sindresorhus/slugify\"\n\n   export const onCreateNode = ({ node, actions }) => {\n     const { createNodeField } = actions\n     if (node.internal.type === `Mdx`) {\n       createNodeField({\n         node,\n         name: `slug`,\n         value: `/${slugify(node.frontmatter.title)}`\n       })\n     }\n   }\n   ```\n\n1. You're now able to query the information on the MDX node:\n   ```graphql\n   query {\n     mdx {\n       fields {\n         slug\n       }\n     }\n   }\n   ```\n\nIf you don't want to use the `frontmatter.title`, adjust what you input to `slugify()`. For example, if you want information from the `File` node, you could use `getNode(node.parent)`.\n\n### headings\n\n1. Install necessary dependencies into your project:\n   ```shell\n   npm install mdast-util-to-string unist-util-visit\n   ```\n1. Create a new file called `remark-headings-plugin.mjs` at the site root:\n\n   ```js:title=remark-headings-plugin.mjs\n   import { visit } from \"unist-util-visit\"\n   import { toString } from \"mdast-util-to-string\"\n\n   const transformer = (tree, file) => {\n     let headings = []\n\n     visit(tree, `heading`, heading => {\n       headings.push({\n         value: toString(heading),\n         depth: heading.depth,\n       })\n     })\n\n     const mdxFile = file\n     if (!mdxFile.data.meta) {\n       mdxFile.data.meta = {}\n     }\n\n     mdxFile.data.meta.headings = headings\n   }\n\n   const remarkHeadingsPlugin = () => transformer\n\n   export default remarkHeadingsPlugin\n   ```\n\n1. Add a new `headings` field resolver to your `Mdx` nodes through `createSchemaCustomization` API:\n\n   ```js:title=gatsby-node.mjs\n   import { compileMDXWithCustomOptions } from \"gatsby-plugin-mdx\"\n   import remarkHeadingsPlugin from \"./remark-headings-plugin.mjs\"\n\n   export const createSchemaCustomization = async ({ getNode, getNodesByType, pathPrefix, reporter, cache, actions, schema, store }) => {\n     const { createTypes } = actions\n\n     const headingsResolver = schema.buildObjectType({\n       name: `Mdx`,\n       fields: {\n         headings: {\n           type: `[MdxHeading]`,\n           async resolve(mdxNode) {\n             const fileNode = getNode(mdxNode.parent)\n\n             if (!fileNode) {\n               return null\n             }\n\n             const result = await compileMDXWithCustomOptions(\n               {\n                 source: mdxNode.body,\n                 absolutePath: fileNode.absolutePath,\n               },\n               {\n                 pluginOptions: {},\n                 customOptions: {\n                   mdxOptions: {\n                     remarkPlugins: [remarkHeadingsPlugin],\n                   },\n                 },\n                 getNode,\n                 getNodesByType,\n                 pathPrefix,\n                 reporter,\n                 cache,\n                 store,\n               }\n             )\n\n             if (!result) {\n               return null\n             }\n\n             return result.metadata.headings\n           }\n         }\n       }\n     })\n\n     createTypes([\n       `\n         type MdxHeading {\n           value: String\n           depth: Int\n         }\n       `,\n       headingsResolver,\n     ])\n   }\n   ```\n\n1. You're now able to query the information on the MDX node:\n   ```graphql\n   query {\n     mdx {\n       headings {\n         value\n         depth\n       }\n     }\n   }\n   ```\n\n## Components\n\nMDX and `gatsby-plugin-mdx` use components for different things like rendering and component mappings.\n\n### MDXProvider\n\n`MDXProvider` is a React component that allows you to replace the\nrendering of tags in MDX content. It does this by providing a list of\ncomponents via context to the internal `MDXTag` component that handles\nrendering of base tags like `p` and `h1`.\n\n```jsx\nimport { MDXProvider } from \"@mdx-js/react\"\n\nconst MyH1 = props => <h1 style={{ color: `tomato` }} {...props} />\nconst MyParagraph = props => (\n  <p style={{ fontSize: \"18px\", lineHeight: 1.6 }} {...props} />\n)\n\nconst components = {\n  h1: MyH1,\n  p: MyParagraph,\n}\n\nexport const ComponentsWrapper = ({ children }) => (\n  <MDXProvider components={components}>{children}</MDXProvider>\n)\n```\n\nThe following components can be customized with the `MDXProvider`:\n\n<!-- prettier-ignore-start -->\n\n| Tag             | Name                                                                 | Syntax                                              |\n| --------------- | -------------------------------------------------------------------- | --------------------------------------------------- |\n| `p`             | [Paragraph](https://github.com/syntax-tree/mdast#paragraph)          |                                                     |\n| `h1`            | [Heading 1](https://github.com/syntax-tree/mdast#heading)            | `#`                                                 |\n| `h2`            | [Heading 2](https://github.com/syntax-tree/mdast#heading)            | `##`                                                |\n| `h3`            | [Heading 3](https://github.com/syntax-tree/mdast#heading)            | `###`                                               |\n| `h4`            | [Heading 4](https://github.com/syntax-tree/mdast#heading)            | `####`                                              |\n| `h5`            | [Heading 5](https://github.com/syntax-tree/mdast#heading)            | `#####`                                             |\n| `h6`            | [Heading 6](https://github.com/syntax-tree/mdast#heading)            | `######`                                            |\n| `thematicBreak` | [Thematic break](https://github.com/syntax-tree/mdast#thematicbreak) | `***`                                               |\n| `blockquote`    | [Blockquote](https://github.com/syntax-tree/mdast#blockquote)        | `>`                                                 |\n| `ul`            | [List](https://github.com/syntax-tree/mdast#list)                    | `-`                                                 |\n| `ol`            | [Ordered list](https://github.com/syntax-tree/mdast#list)            | `1.`                                                |\n| `li`            | [List item](https://github.com/syntax-tree/mdast#listitem)           |                                                     |\n| `table`         | [Table](https://github.com/syntax-tree/mdast#table)                  | `--- | --- | ---`                                   |\n| `tr`            | [Table row](https://github.com/syntax-tree/mdast#tablerow)           | `This | is | a | table row`                         |\n| `td`/`th`       | [Table cell](https://github.com/syntax-tree/mdast#tablecell)         |                                                     |\n| `pre`           | [Pre](https://github.com/syntax-tree/mdast#code)                     |                                                     |\n| `code`          | [Code](https://github.com/syntax-tree/mdast#code)                    |                                                     |\n| `em`            | [Emphasis](https://github.com/syntax-tree/mdast#emphasis)            | `_emphasis_`                                        |\n| `strong`        | [Strong](https://github.com/syntax-tree/mdast#strong)                | `**strong**`                                        |\n| `delete`        | [Delete](https://github.com/syntax-tree/mdast#delete)                | `~~strikethrough~~`                                 |\n| `hr`            | [Break](https://github.com/syntax-tree/mdast#break)                  | `---`                                               |\n| `a`             | [Link](https://github.com/syntax-tree/mdast#link)                    | `<https://mdxjs.com>` or `[MDX](https://mdxjs.com)` |\n| `img`           | [Image](https://github.com/syntax-tree/mdast#image)                  | `![alt](https://mdx-logo.now.sh)`                   |\n<!-- prettier-ignore-end -->\n\nIt's important to define the `components` you pass in a stable way\nso that the references don't change if you want to be able to navigate\nto a hash. That's why we defined `components` outside of any render\nfunctions in these examples.\n\n### Shortcodes\n\nIf you want to allow usage of a component from anywhere (often referred to as a shortcode), you can pass it to the [MDXProvider](https://www.gatsbyjs.com/docs/how-to/routing/mdx#make-components-available-globally-as-shortcodes).\n\n```jsx:title=src/components/layout.jsx\nimport React from \"react\"\nimport { MDXProvider } from \"@mdx-js/react\"\nimport { Link } from \"gatsby\"\nimport { YouTube, Twitter, TomatoBox } from \"./ui\"\n\nconst shortcodes = { Link, YouTube, Twitter, TomatoBox }\n\nexport const Layout = ({ children }) => (\n  <MDXProvider components={shortcodes}>{children}</MDXProvider>\n)\n```\n\nThen, in any MDX file, you can navigate using `Link` and render `YouTube`, `Twitter`, and `TomatoBox` components without\nan import.\n\n```mdx\n# Hello, world!\n\nHere's a YouTube embed\n\n<TomatoBox>\n  <YouTube id=\"123abc\" />\n</TomatoBox>\n```\n\nRead more about injecting your own components in the [official MDX provider guide](https://mdxjs.com/docs/using-mdx/#mdx-provider).\n\n## Migrating from v3 to v4\n\n`gatsby-plugin-mdx@^4.0.0` is a complete rewrite of the original plugin with the goal of making the plugin faster, compatible with [MDX v2](https://mdxjs.com/blog/v2/), leaner, and more maintainable. While doing this rewrite we took the opportunity to fix long-standing issues and remove some functionalities that we now think should be handled by the user, not the plugin. In doing so there will be of course breaking changes you'll have to handle – but with the help of this migration guide and the codemods you'll be on the new version in no time!\n\n### Updating dependencies\n\n```shell\nnpm remove @mdx-js/mdx\nnpm install gatsby-plugin-mdx@latest @mdx-js/react@latest\n```\n\nIf you used any related plugins like `gatsby-remark-images`, also update them to their `@latest` version.\n\n### New options in `gatsby-config`\n\n- Move your `remarkPlugins` and `rehypePlugins` keys into the new `mdxOptions` config option:\n\n  ```diff\n  const config = {\n    plugins: [\n      {\n        resolve: `gatsby-plugin-mdx`,\n        options: {\n  -       remarkPlugins: [],\n  -       rehypePlugins: [],\n  +       mdxOptions: {\n  +         remarkPlugins: [],\n  +         rehypePlugins: [],\n  +       },\n        },\n      },\n    ],\n  }\n\n  export default config\n  ```\n\n- There's a new option called `mdxOptions` which is passed directly to the MDX compiler. See all available options in [the official documentation of `@mdx-js/mdx`](https://mdxjs.com/packages/mdx/#compilefile-options).\n- Only `extensions`, `gatsbyRemarkPlugins`, and `mdxOptions` exist as options now. Every other option got removed, including `defaultLayouts`. See the [layouts guide](#layouts) to learn how to use layouts with `gatsby-plugin-mdx@^4.0.0`.\n- Make sure that any `gatsby-remark-*` plugins are only listed inside the `gatsbyRemarkPlugins` array of `gatsby-plugin-mdx`, not inside the `plugins` array of `gatsby-config` or in any other place.\n\n### GFM & ESM-only packages\n\n- [GitHub flavored markdown (GFM)](https://mdxjs.com/guides/gfm/) support was removed from MDX v2. You can re-enable it with [`mdxOptions`](#mdxoptions) (you have to install `remark-gfm`)\n- Most of the remark ecosystem is ESM so just using the latest package version of `remark-*`/`rehype-*` most probably won't work. Check out the workarounds mentioned in [`mdxOptions`](#mdxoptions)\n\n### Updating `createPage` action in `gatsby-node`\n\nIn most cases the changes necessary here are related to the removal of `defaultLayouts` option and the new way how layouts are done. See the [layouts guide](#layouts) to learn how to use layouts with `gatsby-plugin-mdx@^4.0.0`.\n\nYou'll need to do two things to continue using your old layout file:\n\n1. You need to query the absolute path to the MDX file\n1. You have to attach this MDX file via the `__contentFilePath` query param to your layout file\n\n```diff\nconst postTemplate = path.resolve(`./src/templates/post.jsx`)\n\nactions.createPage({\n-  component: postTemplate,\n+  component: `${postTemplate}?__contentFilePath=/path/to/content.mdx`,\n})\n```\n\nOr a more complete example:\n\n```js\nconst postTemplate = path.resolve(`./src/templates/post.jsx`)\n\n// Rest of createPages API...\n\nconst { data } = await graphql(`\n  {\n    allMdx {\n      nodes {\n        id\n        frontmatter {\n          slug\n        }\n// highlight-start\n        internal {\n          contentFilePath\n        }\n// highlight-end\n      }\n    }\n  }\n`)\n\ndata.allMdx.nodes.forEach(node => {\n  actions.createPage({\n    path: node.frontmatter.slug,\n    component: `${postTemplate}?__contentFilePath=${node.internal.contentFilePath}`, // highlight-line\n    context: {\n      id: node.id,\n    },\n  })\n})\n```\n\nYou'll also need to update your template file itself, see the next section [Updating page templates](#updating-page-templates).\n\nNote: You could also directly pass the MDX file to the `component` like this:\n\n```js\nactions.createPage({\n  component: `/path/to/content.mdx`,\n  // If you don't want to construct it yourself, use internal.contentFilePath\n  // component: node.internal.contentFilePath\n})\n```\n\nHowever, we'd recommend placing such files into the `src/pages` directory and `gatsby-plugin-mdx` will handle the page creation itself.\n\n### Updating page templates\n\n1. Instead of querying for the `body` on the MDX node, the page template now receives the transformed MDX as `children` property.\n1. You no longer need to use `<MDXRenderer>` as you can use `{children}` directly.\n\n```diff\nimport React from \"react\"\nimport { graphql } from \"gatsby\"\n- import { MDXRenderer } from \"gatsby-plugin-mdx\"\n\n- function PostTemplate({ data: { mdx } }) {\n+ function PostTemplate({ data: { mdx }, children }) {\n\n  return (\n    <main>\n      <h1>{mdx.frontmatter.title}</h1>\n-     <MDXRenderer>\n-       {mdx.body}\n-     </MDXRenderer>\n+     {children}\n    </main>\n  )\n}\n\n export const pageQuery = graphql`\n  query PostTemplate($id: String!) {\n    mdx(id: { eq: $id }) {\n      frontmatter {\n        title\n      }\n-     body\n    }\n  }\n`\n\nexport default PostTemplate\n```\n\n### Updating MDX content\n\nAs MDX v2 changed the way it handles content you might need to update your MDX files to be valid MDX now. See their [Update MDX content guide](https://mdxjs.com/migrating/v2/#update-mdx-content) for all details. In [What is MDX?](https://mdxjs.com/docs/what-is-mdx/#markdown) it is also laid out which features don't work. Most importantly for this migration:\n\n- HTML syntax doesn’t work in MDX as it’s replaced by JSX (`<img>` to `<img />`). Instead of HTML comments, you can use JavaScript comments in braces: `{/* comment! */}`\n- Unescaped left angle bracket / less than (`<`) and left curly brace (`{`) have to be escaped: `\\<` or `\\{` (or use expressions: `{'<'}`, `{'{'}`)\n  - If you're using the `enableCustomId` option from `gatsby-remark-autolink-headers` you'll run into problems due to the above. You need to disable this option and use [`rehype-slug-custom-id`](https://github.com/unicorn-utterances/rehype-slug-custom-id) instead.\n\nIn our testing, most of the time the issue were curly brackets that needed to be escaped with backticks:\n\n```diff\n- You can upload this to Git{Hub,Lab}\n+ You can upload this to `Git{Hub,Lab}`\n```\n\nYou can also use [`eslint-mdx`](https://github.com/mdx-js/eslint-mdx) to find all culprits and in some cases automatically fix them through ESLint.\n\n### Updating MDX nodes\n\nSince most MDX nodes are moved to userland you'll have to [extend the GraphQL MDX nodes](#extending-the-graphql-mdx-nodes) and update your queries accordingly. However, you can [alias your `fields`](https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization/#aliasing-fields) to have them at the root of the GraphQL node.\n\nHere's an example of an updated query (if you re-implemented most features):\n\n```diff\n {\n-  timeToRead\n-  rawBody\n-  slug\n   headings\n-  html\n-  mdxAST\n-  wordCount\n-  fileAbsolutePath\n+  body\n+  fields {\n+    timeToRead\n+    slug\n+  }\n+  internal {\n+    contentFilePath\n+  }\n }\n```\n\nHere's an example on how you'd alias your `fields` to keep the shape of the MDX node the same:\n\n```js:title=gatsby-node.mjs\nimport readingTime from \"reading-time\"\n\nexport const onCreateNode = ({ node, actions }) => {\n  const { createNodeField } = actions\n  if (node.internal.type === `Mdx`) {\n    createNodeField({\n      node,\n      name: `timeToRead`,\n      value: readingTime(node.body)\n    })\n  }\n}\n\nexport const createSchemaCustomization = ({ actions }) => {\n  const { createTypes } = actions\n\n  createTypes(`#graphql\n    type Mdx implements Node {\n      # You can also use other keys from fields.timeToRead if you don't want \"minutes\"\n      timeToRead: Float @proxy(from: \"fields.timeToRead.minutes\")\n      wordCount: Int @proxy(from: \"fields.timeToRead.words\")\n    }\n  `)\n}\n```\n\n### v3 to v4: Breaking Changes\n\n- Removed plugin options: `defaultLayouts`, `mediaTypes`, `lessBabel`, `shouldBlockNodeFromTransformation`, `commonmark`\n- Moved plugin options `remarkPlugins` and `rehypePlugins` into `mdxOptions`\n- Removed `timeToRead`, `rawBody`, `slug`, `headings`, `html`, `mdxAST`, `wordCount`, `fileAbsolutePath` from the query result. You can check [Extending the GraphQL MDX nodes](#extending-the-graphql-mdx-nodes) to learn how to re-implement some of them on your own. Also check [Updating MDX nodes](#updating-mdx-nodes) for guidance on changing your queries\n- `gatsby-plugin-mdx` only applies to local files (that are sourced with `gatsby-source-filesystem`)\n- Removed the ability to use `js` and `json` in frontmatter\n- Loading MDX from other sources as the filesystem is not supported. If you have a need for that, please comment in the [GitHub Discussion](https://github.com/gatsbyjs/gatsby/discussions/25068)\n- All [MDX v2 migration](https://mdxjs.com/migrating/v2/) notes apply\n\nAs mentioned above the `html` field was removed from the GraphQL node. We know that some of you used this for e.g. `gatsby-plugin-feed`. Unfortunately, for compatibility and performance reasons we had to remove it. We recommend using the `excerpt` field in the meantime until we find a feasible solution to provide MDX rendered as HTML. If you have any suggestions, please comment on the [GitHub Discussion](https://github.com/gatsbyjs/gatsby/discussions/25068).\n\n## Why MDX?\n\nBefore MDX, some of the benefits of writing Markdown were lost when integrating with JSX. Implementations were often template string-based which required lots of escaping and cumbersome syntax.\n\nMDX seeks to make writing with Markdown and JSX simpler while being more expressive. Writing is fun again when you combine components, that can even be dynamic or load data, with the simplicity of Markdown for long-form content.\n\n## Related\n\n- [What is MDX](https://mdxjs.com/docs/what-is-mdx/)\n- [Using MDX](https://mdxjs.com/docs/using-mdx/)\n- [Troubleshooting MDX](https://mdxjs.com/docs/troubleshooting-mdx/)\n- [Adding MDX Pages](https://www.gatsbyjs.com/docs/how-to/routing/mdx/)\n","publish_time":1764019191519,"_cnpm_publish_time":1764019191519,"dist-tags":{"alpha-9689ff":"4.2.0-alpha-9689ff.25","alpha-a5-peer":"4.2.0-alpha-a5-peer.54","alpha-mdx-v2":"3.18.0-alpha-mdx-v2.68","alpha-parallel":"2.2.0-alpha-parallel.29","alpha-parallel-query":"2.6.0-alpha-parallel-query.75","alpha-qe-sm":"2.14.0-alpha-qe-sm.46","alpha-remote-fetch":"2.14.0-alpha-remote-fetch.79","alpha-remote-file":"2.10.0-alpha-remote-file.48","alpha-sharp-upgrade":"2.3.0-alpha-sharp-upgrade.15","alpha-trailing-slash":"3.5.0-alpha-trailing-slash.71","alpha-transformer-json":"3.14.0-alpha-transformer-json.26","alpha-ts-jit":"3.6.0-alpha-ts-jit.26","alpha-v4":"4.0.0-alpha-v4.27","alpha-v5":"5.0.0-alpha-v5.d20221012t101120.57","alt-image-cdn":"5.13.0-alpha-alt-image-cdn.44","berry-mdx":"1.0.68-berry-mdx.56","coreutils":"2.12.0-coreutils.29","dev-ssr-2":"1.2.36-dev-ssr-2.60","drupal-image-404":"3.17.0-alpha-drupal-image-404.12","drupal-next":"2.14.0-drupal-next.94","drupal-proxyurl":"5.0.0-alpha-drupal-proxyurl.14","drupal-self-reference":"3.18.0-alpha-drupal-self-reference.18","functions-next":"2.4.0-functions-next.18","image-cdn":"3.9.0-alpha-image-cdn.39","image-cdn-caching":"3.16.0-alpha-image-cdn-caching.9","image-cdn-configurable":"5.9.0-image-cdn-configurable.4","image-cdn-enc":"4.2.0-alpha-image-cdn-enc.24","image-cdn-jobs-resolve":"3.18.0-alpha-image-cdn-jobs-resolve.32","image-cdn-pathprefix":"4.4.0-alpha-image-cdn-pathprefix.48","image-cdn-telemetry":"3.13.0-alpha-image-cdn-telemetry.29","image-service":"3.8.0-alpha-image-service.35","incbuild-collections":"1.2.35-incbuild-collections.159","latest":"5.16.0","latest-v3":"2.15.0","latest-v4":"4.4.0","luda":"3.11.0-alpha-luda.30","mdx-less-babel":"1.2.23-mdx-less-babel.68","mdx-less-babel2":"1.2.23-mdx-less-babel2.69","mdxv4-rc":"4.0.0-rc.3","next":"5.17.0-next.0","otp-test":"1.0.33-otp-test.13","pr-20741":"1.0.70-pr-20741.67","preview-gh-api":"4.2.0-alpha-preview-gh-api.26","prompt-restart":"1.1.4-prompt-restart.100","query-webpack-modules":"1.2.47-query-webpack-modules.63","rc":"1.0.2-1","react19":"5.18.0-react19.2","state-machine":"1.0.85-state-machine.75","telemetry-test":"1.5.0-telemetry-test.315","unifiedroutes":"1.1.9-unifiedroutes.96","unifiedroutes-v2":"1.1.9-unifiedroutes-v2.135","v3rc":"2.0.0-v3rc.0","wordpress-image-err":"4.3.1-alpha-wordpress-image-err.27","wp-image-cdn-auth":"3.15.0-alpha-wp-image-cdn-auth.46"}}