Project: syntax-tree/mdast-util-frontmatter

Package: mdast-util-frontmatter@1.0.0

  1. Dependents: 2
  2. mdast extension to parse and serialize frontmatter (YAML, TOML, etc)
  1. util 143
  2. utility 139
  3. markdown 132
  4. unist 126
  5. mdast 85
  6. mdast-util 30
  7. markup 18
  8. gfm 18
  9. frontmatter 7
  10. yaml 7
  11. toml 4


Build Coverage Downloads Size Sponsors Backers Chat

Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support frontmatter in mdast. When parsing (from-markdown), must be combined with micromark-extension-frontmatter.

When to use this

Use this if you’re dealing with the AST manually. It’s probably nicer to use remark-frontmatter with remark, which includes this but provides a nicer interface and makes it easier to combine with hundreds of plugins.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install mdast-util-frontmatter


Say we have the following file, example.md:

title = "New Website"

# Other markdown

And our module, example.js, looks as follows:

import fs from 'node:fs'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toMarkdown} from 'mdast-util-to-markdown'
import {frontmatter} from 'micromark-extension-frontmatter'
import {frontmatterFromMarkdown, frontmatterToMarkdown} from 'mdast-util-frontmatter'

const doc = fs.readFileSync('example.md')

const tree = fromMarkdown(doc, {
  extensions: [frontmatter(['yaml', 'toml'])],
  mdastExtensions: [frontmatterFromMarkdown(['yaml', 'toml'])]


const out = toMarkdown(tree, {extensions: [frontmatterToMarkdown(['yaml', 'toml'])]})


Now, running node example yields:

  type: 'root',
  children: [
    {type: 'toml', value: 'title = "New Website"'},
      type: 'heading',
      depth: 1,
      children: [{type: 'text', value: 'Other markdown'}]
title = "New Website"

# Other markdown


This package exports the following identifiers: frontmatterFromMarkdown, frontmatterToMarkdown. There is no default export.



Support frontmatter (YAML, TOML, and more). These functions can be called with options and return extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.

Options are the same as micromark-extension-frontmatter.


See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer