From c6ed99b13b53faf382b5ec907a6790505ed8ac5a Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 14 May 2023 20:09:41 +0200 Subject: [PATCH 1/4] [docs] Clarify that merely changing `extension` does not load `.md` files as MDX I got bitten by this passage because it reads as if merely changing the `extension` setting will cause `.md` files to be loaded as MDX. See: https://github.com/mdx-js/mdx/issues/2302 --- packages/next-mdx/readme.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/next-mdx/readme.md b/packages/next-mdx/readme.md index 250906682e3b..aa8feaf77f8f 100644 --- a/packages/next-mdx/readme.md +++ b/packages/next-mdx/readme.md @@ -51,7 +51,7 @@ module.exports = withMDX({ }) ``` -Optionally you can match other file extensions for MDX compilation, by default only `.mdx` is supported +Optionally you can match other file extensions for MDX compilation, as by default only `.mdx` is supported: ```js // next.config.js @@ -61,6 +61,21 @@ const withMDX = require('@next/mdx')({ module.exports = withMDX() ``` +The configuration above will load both `.md` and `.mdx` files. However, please note that even with this configuration in place, MDX will load `.md` files as Markdown (not as MDX) because by default it will auto-detect the type. +If you want to load `.md` files as MDX content, you should in addition configure [the `format` option](https://mdxjs.com/packages/mdx/#optionsformat) and set it to `mdx`: + +```js +// next.config.js +const withMDX = require('@next/mdx')({ + extension: /\.(md|mdx)$/, + options: { + format: 'mdx' + } +}) +module.exports = withMDX() +``` + + ## Top level .mdx pages Define the `pageExtensions` option to have Next.js handle `.md` and `.mdx` files in the `pages` directory as pages: From d1c3f6f512c940b5e5c07dd8f0c03582efa090b8 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Mon, 15 May 2023 10:25:13 +0200 Subject: [PATCH 2/4] Update packages/next-mdx/readme.md Co-authored-by: Christian Murphy --- packages/next-mdx/readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/next-mdx/readme.md b/packages/next-mdx/readme.md index aa8feaf77f8f..5fe4a0c64e6a 100644 --- a/packages/next-mdx/readme.md +++ b/packages/next-mdx/readme.md @@ -51,7 +51,9 @@ module.exports = withMDX({ }) ``` -Optionally you can match other file extensions for MDX compilation, as by default only `.mdx` is supported: +By default MDX will only match and compile MDX files with the `.mdx` extension. +However, it can also be optionally configured to handle markdown files with the `.md` extension, as shown below: + ```js // next.config.js From f0f2c984cd7d8467556cc992e497fda651cfda19 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Mon, 15 May 2023 10:31:53 +0200 Subject: [PATCH 3/4] Update packages/next-mdx/readme.md Co-authored-by: Christian Murphy --- packages/next-mdx/readme.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/packages/next-mdx/readme.md b/packages/next-mdx/readme.md index 5fe4a0c64e6a..6e8e98004e68 100644 --- a/packages/next-mdx/readme.md +++ b/packages/next-mdx/readme.md @@ -63,19 +63,7 @@ const withMDX = require('@next/mdx')({ module.exports = withMDX() ``` -The configuration above will load both `.md` and `.mdx` files. However, please note that even with this configuration in place, MDX will load `.md` files as Markdown (not as MDX) because by default it will auto-detect the type. -If you want to load `.md` files as MDX content, you should in addition configure [the `format` option](https://mdxjs.com/packages/mdx/#optionsformat) and set it to `mdx`: - -```js -// next.config.js -const withMDX = require('@next/mdx')({ - extension: /\.(md|mdx)$/, - options: { - format: 'mdx' - } -}) -module.exports = withMDX() -``` +In addition, MDX can be customized with compiler options, see the [mdx documentation](https://mdxjs.com/packages/mdx/#compilefile-options) for details on supported options. ## Top level .mdx pages From 1b4aa8601880b525404ab7e2d6458a2fa1e06736 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 13 Jun 2023 22:48:50 -0700 Subject: [PATCH 4/4] lint fix --- packages/next-mdx/readme.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/next-mdx/readme.md b/packages/next-mdx/readme.md index 6e8e98004e68..2b7941901d2c 100644 --- a/packages/next-mdx/readme.md +++ b/packages/next-mdx/readme.md @@ -54,7 +54,6 @@ module.exports = withMDX({ By default MDX will only match and compile MDX files with the `.mdx` extension. However, it can also be optionally configured to handle markdown files with the `.md` extension, as shown below: - ```js // next.config.js const withMDX = require('@next/mdx')({ @@ -65,7 +64,6 @@ module.exports = withMDX() In addition, MDX can be customized with compiler options, see the [mdx documentation](https://mdxjs.com/packages/mdx/#compilefile-options) for details on supported options. - ## Top level .mdx pages Define the `pageExtensions` option to have Next.js handle `.md` and `.mdx` files in the `pages` directory as pages: