unified

Project: remcohaszing/remark-mdx-frontmatter

Package: remark-mdx-frontmatter@2.1.1

  1. Dependents: 0
  2. A remark plugin for converting frontmatter metadata into MDX exports
  1. remark 218
  2. unified 184
  3. markdown 162
  4. mdast 91
  5. remark-plugin 84
  6. mdx 39
  7. frontmatter 7
  8. yaml 7
  9. toml 4

remark-mdx-frontmatter

github actions npm prettier codecov

A remark plugin for converting frontmatter metadata into MDX exports

Table of Contents

Installation

This package depends on the AST output by remark-frontmatter

npm install remark-frontmatter remark-mdx-frontmatter

Usage

This remark plugin takes frontmatter content, and outputs it as JavaScript exports. Both YAML and TOML frontmatter data are supported.

For example, given a file named example.mdx with the following contents:

---
hello: frontmatter
---

Rest of document

The following script:

import { readFile } from 'node:fs/promises'

import { compile } from '@mdx-js/mdx'
import remarkFrontmatter from 'remark-frontmatter'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'

const { contents } = await compile(await readFile('example.mdx'), {
  jsx: true,
  remarkPlugins: [remarkFrontmatter, remarkMdxFrontmatter]
})
console.log(contents)

Roughly yields:

export const frontmatter = {
  hello: 'frontmatter'
}

export default function MDXContent() {
  return <p>Rest of document</p>
}

API

The default export is a remark plugin.

Options

License

MIT © Remco Haszing