unified

Project: micromark/micromark-extension-frontmatter

Package: micromark-extension-frontmatter@0.2.2

  1. Dependencies: 1·Dependents: 2
  2. micromark extension to support frontmatter (YAML, TOML, etc)
  1. unified 169
  2. markdown 142
  3. gfm 18
  4. micromark 16
  5. micromark-extension 16
  6. frontmatter 6
  7. yaml 6
  8. toml 3

micromark-extension-frontmatter

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.

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

Install

npm:

npm install micromark-extension-frontmatter

API

html(options)

syntax(options)

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

Support frontmatter (YAML, TOML, and more).

The exports are functions that can be called with options and return extensions for the micromark parser (to tokenize frontmatter; can be passed in extensions) and the default HTML compiler (to ignore frontmatter; can be passed in htmlExtensions).

options

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

preset

Either 'yaml' or 'toml':

Matter

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

Example

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

---
key: value
---

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

<<<
data
>>>

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

+=+=+=+
data
+=+=+=+

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

{
  "key": "value"
}

Contribute

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.

License

MIT © Titus Wormer