JSPM

micromark-extension-frontmatter

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1645706
  • Score
    100M100P100Q213881F
  • License MIT

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

Package Exports

  • micromark-extension-frontmatter
  • micromark-extension-frontmatter/lib/matters

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micromark-extension-frontmatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micromark-extension-frontmatter

Build Coverage Downloads Size Sponsors Backers Chat

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

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

As there is no spec for frontmatter in markdown, this extension follows how YAML frontmatter works in markdown on GitHub (🧊). 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 (🧊).

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

syntax(options)

html(options)

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

Support frontmatter (YAML, TOML, and more). These functions can be called with options and return extensions, respectively for the micromark parser, and the html default compiler. The syntax extension, which takes care of parsing the described frontmatter, can be passed in extensions; the HTML extension, which takes care of ignoring said frontmatter, in htmlExtensions.

options

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

preset

Either 'yaml' or 'toml':

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

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
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