Astro M²DX - Remark plugin to inject raw MDX into frontmatter
DEPRECATED: Please consider using the plugin astro-m2dx, which bundles all features from the different
@astro-m2dx
plugins in one plugin (all features are opt-in).
remark plugin to add the raw markdown content to the frontmatter of your Astro MDX files.
Astro M²DX is a set of plugins allowing you to define an Astro
Have a look at the other astro-m2dx
plugins.
Content
What is this?
This package is a remark
plugin to add the raw markdown content to the frontmatter of your MDX files in the context of Astro site generation.
Astro MDX files do not carry the raw MDX content anymore, once you import them. With this plugin you can access the raw content in the frontmatter mdx
property.
When should I use this?
If you want to have access to the raw MDX content while generating your Astro pages.
Install
This package is ESM only.
In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm
:
npm install -D @astro-m2dx/remark-astro-raw-mdx
Use
In your astro.config.mjs
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import rawMdx from '@astro-m2dx/remark-astro-raw-mdx';
// ^^^
// https://astro.build/config
export default defineConfig({
integrations: [mdx()],
markdown: {
remarkPlugins: [rawMdx],
// ^^^
extendDefaultPlugins: true,
},
});
This uses the default options, where the name of the property on the frontmatter is mdx
.
Options
If you want to use a different name for the property, you can specify it in the plugin's name
option like so:
remarkPlugins: [[rawMdx, {property: "raw"}]],