Project: syntax-tree/mdast-util-frontmatter

Package: mdast-util-frontmatter@0.2.0

  1. Dependencies: 1·Dependents: 1
  2. mdast extension to parse and serialize frontmatter (YAML, TOML, etc)
  1. markdown 142
  2. util 128
  3. utility 124
  4. unist 120
  5. mdast 89
  6. mdast-util 29
  7. gfm 18
  8. markup 17
  9. frontmatter 6
  10. yaml 6
  11. toml 3


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.

You probably shouldn’t use this package directly, but instead use remark-frontmatter with remark.



npm install mdast-util-frontmatter


Say we have the following file, example.md:

title = "New Website"

# Other markdown

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

var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-frontmatter')
var frontmatter = require('mdast-util-frontmatter')

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

var tree = fromMarkdown(doc, {
  extensions: [syntax(['yaml', 'toml'])],
  mdastExtensions: [frontmatter.fromMarkdown(['yaml', 'toml'])]


var out = toMarkdown(tree, {extensions: [frontmatter.toMarkdown(['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




Note: the separate extensions are also available at mdast-util-frontmatter/from-markdown and mdast-util-frontmatter/to-markdown.

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