micromark extension to support frontmatter (YAML, TOML, etc)


901.0.05 months agoa year agoMinified + gzip package size for micromark-extension-frontmatter in KB



Build Coverage Downloads Size Sponsors Backers Chat

micromark extension to support frontmatter (YAML, TOML, etc).

As there is no spec for frontmatter in markdown, this extension follows how YAML frontmatter works on github.com. For the HTML part, instead of rendering YAML, it is ignored. Other types of frontmatter can be parsed, which will by default also work the same as on github.com.

This package provides the low-level modules for integrating with the micromark tokenizer and the micromark HTML compiler.

When to use this

If you’re using micromark or mdast-util-from-markdown, use this package. Alternatively, if you’re using remark, use remark-frontmatter.


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


npm install micromark-extension-frontmatter


import {micromark} from 'micromark'
import {frontmatter, frontmatterHtml} from 'micromark-extension-frontmatter'

const output = micromark('---\na: b\n---\n# c', {
  extensions: [frontmatter()],
  htmlExtensions: [frontmatterHtml()]





This package exports the following identifiers: frontmatter, frontmatterHtml. There is no default export.

The export map supports the endorsed development condition. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.



Note: syntax is the default export of this module, html is available at micromark-extension-frontmatter/html.

Support frontmatter (YAML, TOML, and more).

Two functions that can be called with options to get an extension for micromark to parse frontmatter (can be passed in extensions) and one to compile (ignore) them (can be passed in htmlExtensions).


One preset or Matter, or an array of them, defining all the supported frontmatters (default: 'yaml').


Either 'yaml' or 'toml':

  • 'yaml'matter defined as {type: 'yaml', marker: '-'}
  • 'toml'matter defined as {type: 'toml', marker: '+'}

An object with a type and either a marker or a fence:

  • type (string) — Type to tokenize as
  • marker (string or {open: string, close: string}) — Character used to construct fences. By providing an object with open and close different characters can be used for opening and closing fences. For example the character '-' will result in '---' being used as the fence
  • fence (string or {open: string, close: string}) — String used as the complete fence. By providing an object with open and close different values can be used for opening and closing fences. This can be used too if fences contain different characters or lengths other than 3
  • anywhere (boolean, default: false) – if true, matter can be found anywhere in the document. If false (default), only matter at the start of the document is recognized

For {type: 'yaml', marker: '-'}:

key: value

For {type: 'custom', marker: {open: '<', close: '>'}}:


For {type: 'custom', fence: '+=+=+=+'}:


For {type: 'json', fence: {open: '{', close: '}'}}:

  "key": "value"



See contributing.md in micromark/.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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.