Frontmatter (YAML, TOML, and more) support for remark.
npm:
npm install remark-frontmatterSay we have the following file, example.md:
+++
title = "New Website"
+++
# Other markdownAnd 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.log(String(file))
console.error(report(err || 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: [Object] }example.md: no issues found
+++
title = "New Website"
+++
# Other markdownAdds tokenizers if the processor is configured with
remark-parse, and visitors if configured with
remark-stringify.
If you are parsing from a different syntax, or compiling to a different syntax
(e.g., remark-man) your custom nodes may not be supported.
One preset or Matter, or an array of them, defining all
the supported frontmatters (default: 'yaml').
Either 'yaml' or 'toml':
'yaml'—matterdefined as{type: 'yaml', marker: '-'}'toml'—matterdefined as{type: 'toml', marker: '+'}
An object with a type and either a marker or a fence:
type(string) — Node type to parse to in mdast and compile frommarker(stringor{open: string, close: string}) — Character used to construct fences. By providing an object withopenandclose. different characters can be used for opening and closing fences. For example the character'-'will result in'---'being used as the fencefence(stringor{open: string, close: string}) — String used as the complete fence. By providing an object withopenandclosedifferent values can be used for opening and closing fences. This can be used too if fences contain different characters or lengths other than 3anywhere(boolean, default:false) – iftrue, matter can be found anywhere in the document. Iffalse(default), only matter at the start of the document is recognised.
For {type: 'yaml', marker: '-'}:
---
key: value
---Yields:
{
"type": "yaml",
"value": "key: value"
}For {type: 'custom', marker: {open: '<', close: '>'}}:
<<<
data
>>>
Yields:
{
"type": "custom",
"value": "data"
}For {type: 'custom', fence: '+=+=+=+'}:
+=+=+=+
data
+=+=+=+
Yields:
{
"type": "custom",
"value": "dats"
}For {type: 'json', fence: {open: '{', close: '}'}}:
{
"key": "value"
}Yields:
{
"type": "json",
"value": "\"key\": \"value\""
}remark-github— Auto-link references like in GitHub issues, PRs, and commentsremark-math— Math supportremark-yaml-config— Configure remark from YAML configuration
See contributing.md in remarkjs/remark for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.