JSPM

mdast-util-frontmatter

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1847237
  • Score
    100M100P100Q217907F
  • License MIT

mdast extension to parse and serialize frontmatter (YAML, TOML, etc)

Package Exports

  • mdast-util-frontmatter

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 (mdast-util-frontmatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mdast-util-frontmatter

Build Coverage Downloads Size Sponsors Backers Chat

Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support frontmatter in mdast. When parsing (from-markdown), must be combined with micromark-extension-frontmatter.

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

Install

npm:

npm install mdast-util-frontmatter

Use

Say we have the following file, example.md:

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

# Other markdown

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

var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-frontmatter')
var frontmatter = require('mdast-util-frontmatter')

var doc = fs.readFileSync('example.md')

var tree = fromMarkdown(doc, {
  extensions: [syntax(['yaml', 'toml'])],
  mdastExtensions: [frontmatter.fromMarkdown(['yaml', 'toml'])]
})

console.log(tree)

var out = toMarkdown({extensions: [frontmatter.toMarkdown(['yaml', 'toml'])]})

console.log(out)

Now, running node example yields:

{
  type: 'root',
  children: [
    {type: 'toml', value: 'title = "New Website"'},
    {
      type: 'heading',
      depth: 1,
      children: [{type: 'text', value: 'Other markdown'}]
    }
  ]
}
+++
title = "New Website"
+++

# Other markdown

API

frontmatter.fromMarkdown([options])

frontmatter.toMarkdown([options])

Note: the separate extensions are also available at mdast-util-frontmatter/from-markdown and mdast-util-frontmatter/to-markdown.

Support frontmatter (YAML, TOML, and more). These functions can be called with options and return extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.

Options are the same as micromark-extension-frontmatter.

Contribute

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