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
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
andmdast-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
.
Related
remarkjs/remark
— markdown processor powered by pluginsremarkjs/remark-frontmatter
— remark plugin to support frontmattermicromark/micromark
— the smallest commonmark-compliant markdown parser that existsmicromark/micromark-extension-frontmatter
— micromark extension to parse frontmattersyntax-tree/mdast-util-from-markdown
— mdast parser usingmicromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdast
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.