MDX is an extension of Markdown that allows you to import and write JSX in your markdown documents.
Markdown can be used for creating web pages, documents or any text that needs to be transformed into other formats like For web applications, Markdown needs to be transformed into HTML. But, Using Markdown you can only use HTML elements.
MDX is an extension of Markdown that allows you to import and write JSX in your markdown documents. So, MDX takes the format a step further and allows us to include our own custom React components!
Today, MDX Bundler is arguably the best option for processing MDX in a Nextjs applicattion. mdx-bundler uses esbuild, so it's VERY fast and supports TypeScript files (for the dependencies of your MDX files). It also uses xdm which is a more modern and powerful MDX compiler with no extra runtime requirements.
Here we go -
Install the dependencies for mdx-bundler
Create a directory with MDX files
Install necessary Plugins
- reading-time Estimate an article's reading time
- gray-matter Extend front-matter metadata
- rehype-slug Plugin to add id's to headings
- rehype-code-titles Plugin to add titles for code blocks
- rehype-prism-plus Plugin to add code highlighting
- rehype-autolink-headings Plugin to automatically add link to headings