Wondering what’s next for npm?Check out our public roadmap! »

    remark-frontmatter
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.0 • Public • Published

    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

    npm:

    npm install remark-frontmatter

    Use

    Say we have the following file, example.md:

    +++
    title = "New Website"
    +++
     
    Other markdown

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

    var vfile = require('to-vfile')
    var report = require('vfile-reporter')
    var unified = require('unified')
    var parse = require('remark-parse')
    var stringify = require('remark-stringify')
    var frontmatter = require('remark-frontmatter')
     
    unified()
      .use(parse)
      .use(stringify)
      .use(frontmatter, ['yaml', 'toml'])
      .use(logger)
      .process(vfile.readSync('example.md'), function (err, file) {
        console.error(report(err || file))
        console.log(String(file))
      })
     
    function logger() {
      return console.dir
    }

    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

    remark().use(frontmatter[, 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.

    Related

    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

    Install

    npm i remark-frontmatter

    DownloadsWeekly Downloads

    170,285

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    10.6 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar
    • avatar