Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
micromark-extension-frontmatter
Advanced tools
micromark extension to support frontmatter (YAML, TOML, etc)
The micromark-extension-frontmatter package is an extension for micromark, a Markdown parser, that allows for the parsing of frontmatter. Frontmatter is metadata at the beginning of a Markdown file, typically used for configuration or data storage purposes.
Parsing YAML Frontmatter
This feature allows you to parse YAML frontmatter in a Markdown file. The code sample demonstrates how to use the micromark-extension-frontmatter to parse a Markdown string containing YAML frontmatter and convert it to HTML.
const micromark = require('micromark');
const { frontmatter } = require('micromark-extension-frontmatter');
const markdown = `---
title: Example Title
author: John Doe
---
# Hello World
`;
const html = micromark(markdown, {
extensions: [frontmatter()]
});
console.log(html);
Parsing TOML Frontmatter
This feature allows you to parse TOML frontmatter in a Markdown file. The code sample demonstrates how to use the micromark-extension-frontmatter to parse a Markdown string containing TOML frontmatter and convert it to HTML.
const micromark = require('micromark');
const { frontmatter } = require('micromark-extension-frontmatter');
const markdown = `+++
title = "Example Title"
author = "John Doe"
+++
# Hello World
`;
const html = micromark(markdown, {
extensions: [frontmatter('toml')]
});
console.log(html);
Parsing JSON Frontmatter
This feature allows you to parse JSON frontmatter in a Markdown file. The code sample demonstrates how to use the micromark-extension-frontmatter to parse a Markdown string containing JSON frontmatter and convert it to HTML.
const micromark = require('micromark');
const { frontmatter } = require('micromark-extension-frontmatter');
const markdown = `{
"title": "Example Title",
"author": "John Doe"
}
# Hello World
`;
const html = micromark(markdown, {
extensions: [frontmatter('json')]
});
console.log(html);
gray-matter is a popular package for parsing frontmatter from strings or files. It supports YAML, JSON, and TOML frontmatter. Unlike micromark-extension-frontmatter, which is an extension for micromark, gray-matter is a standalone package that can be used independently of any Markdown parser.
front-matter is another package for parsing frontmatter from strings. It supports YAML frontmatter and is simpler and more lightweight compared to gray-matter. It does not support TOML or JSON frontmatter, making it less versatile than micromark-extension-frontmatter.
markdown-it-front-matter is a plugin for the markdown-it Markdown parser that allows for the extraction of frontmatter. It primarily supports YAML frontmatter. This package is similar to micromark-extension-frontmatter in that it is an extension for a specific Markdown parser.
micromark extension to support frontmatter (YAML, TOML, etc).
As there is no spec for frontmatter in markdown, this extension follows how YAML frontmatter works on github.com. For the HTML part, instead of rendering YAML, it is ignored. Other types of frontmatter can be parsed, which will by default also work the same as on github.com.
This package provides the low-level modules for integrating with the micromark tokenizer and the micromark HTML compiler.
You probably shouldn’t use this package directly, but instead use
mdast-util-frontmatter
with mdast or
remark-frontmatter
with remark.
npm:
npm install micromark-extension-frontmatter
html(options)
syntax(options)
Note:
syntax
is the default export of this module,html
is available atmicromark-extension-frontmatter/html
.
Support frontmatter (YAML, TOML, and more).
The exports are functions that can be called with options and return extensions
for the micromark parser (to tokenize frontmatter; can be passed in
extensions
) and the default HTML compiler (to ignore frontmatter; can be
passed in htmlExtensions
).
options
One preset
or Matter
, or an array of them, defining all
the supported frontmatters (default: 'yaml'
).
preset
Either 'yaml'
or 'toml'
:
'yaml'
— matter
defined as {type: 'yaml', marker: '-'}
'toml'
— matter
defined as {type: 'toml', marker: '+'}
Matter
An object with a type
and either a marker
or a fence
:
type
(string
)
— Type to tokenize asmarker
(string
or {open: string, close: string}
)
— Character used to construct fences.
By providing an object with open
and close
.
different characters can be used for opening and closing fences.
For example the character '-'
will result in '---'
being used as the
fencefence
(string
or {open: string, close: string}
)
— String used as the complete fence.
By providing an object with open
and close
different 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
)
– if true
, matter can be found anywhere in the document.
If false
(default), only matter at the start of the document is recognizedFor {type: 'yaml', marker: '-'}
:
---
key: value
---
For {type: 'custom', marker: {open: '<', close: '>'}}
:
<<<
data
>>>
For {type: 'custom', fence: '+=+=+=+'}
:
+=+=+=+
data
+=+=+=+
For {type: 'json', fence: {open: '{', close: '}'}}
:
{
"key": "value"
}
remarkjs/remark
— markdown processor powered by pluginsmicromark/micromark
— the smallest commonmark-compliant markdown parser that existsremarkjs/remark-frontmatter
— remark plugin to support frontmattersyntax-tree/mdast-util-frontmatter
— mdast utility to support frontmattersyntax-tree/mdast-util-from-markdown
— mdast parser using micromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdastSee contributing.md
in micromark/.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.
FAQs
micromark extension to support frontmatter (YAML, TOML, etc)
The npm package micromark-extension-frontmatter receives a total of 897,660 weekly downloads. As such, micromark-extension-frontmatter popularity was classified as popular.
We found that micromark-extension-frontmatter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.