unified

Project: remarkjs/remark-frontmatter

Package: remark-frontmatter@4.0.0

  1. Dependents: 237
  2. remark plugin to support frontmatter (yaml, toml, and more)
  1. remark 187
  2. unified 175
  3. plugin 136
  4. markdown 132
  5. mdast 85
  6. remark-plugin 68
  7. frontmatter 7
  8. yaml 7
  9. toml 4

remark-frontmatter

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to support frontmatter (YAML, TOML, and more).

Important!

This plugin is affected by the new parser in remark (micromark, see remarkjs/remark#536). Use version 2 while you’re still on remark 12. Use version 3 for remark 13+.

Install

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

npm:

npm install remark-frontmatter

Use

Say we have the following file, example.md:

+++
title = "New Website"
+++

# Other markdown

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

import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkFrontmatter from 'remark-frontmatter'
import remarkStringify from 'remark-stringify'

const file = readSync('example.md')

unified()
  .use(remarkParse)
  .use(remarkStringify)
  .use(remarkFrontmatter, ['yaml', 'toml'])
  .use(() => (tree) => {
    console.dir(tree)
  })
  .process(file)
  .then((file) => {
    console.error(reporter(file))
    console.log(String(file))
  })

Now, running node example yields:

{
  type: 'root',
  children: [
    {type: 'toml', value: 'title = "New Website"', position: [Object]},
    {type: 'heading', depth: 1, children: [Array], position: [Object]}
  ],
  position: {
    start: {line: 1, column: 1, offset: 0},
    end: {line: 6, column: 1, offset: 48}
  }
}
example.md: no issues found
+++
title = "New Website"
+++

# Other markdown

API

This package exports no identifiers. The default export is remarkFrontmatter.

unified().use(remarkFrontmatter[, options])

Configures remark so that it can parse and serialize frontmatter (YAML, TOML, and more).

options

See micromark-extension-frontmatter for a description of options.

Security

Use of remark-frontmatter does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.

Contribute

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