Gathering detailed insights and metrics for micromark-extension-frontmatter
Gathering detailed insights and metrics for micromark-extension-frontmatter
Gathering detailed insights and metrics for micromark-extension-frontmatter
Gathering detailed insights and metrics for micromark-extension-frontmatter
micromark
small commonmark compliant markdown parser with positional info and concrete tokens
micromark-extension-gfm-table
micromark extension to support GFM tables
micromark-extension-gfm-footnote
micromark extension to support GFM footnotes
micromark-extension-gfm-tagfilter
micromark extension to support GFM tagfilter
micromark extension to support frontmatter (YAML, TOML, etc)
npm install micromark-extension-frontmatter
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
20 Stars
74 Commits
2 Forks
7 Watching
1 Branches
12 Contributors
Updated on 16 Nov 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-2.7%
228,123
Compared to previous day
Last week
4.4%
1,325,242
Compared to previous week
Last month
12.7%
5,559,160
Compared to previous month
Last year
75.1%
48,567,323
Compared to previous year
micromark extensions to support frontmatter (YAML, TOML, and more).
This package contains two extensions that add support for frontmatter syntax
as often used in markdown to micromark
.
Frontmatter is a metadata format in front of the content. It’s typically written in YAML and is often used with markdown. Frontmatter does not work everywhere so it makes markdown less portable.
As there is no spec for frontmatter in markdown, these extensions follow how
YAML frontmatter works on github.com
.
It can also parse TOML frontmatter, just like YAML except that it uses a +
.
You can use these extensions when you are working with micromark
already.
When you need a syntax tree, you can combine this package with
mdast-util-frontmatter
.
All these packages are used remark-frontmatter
, which
focusses on making it easier to transform content by abstracting these
internals away.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install micromark-extension-frontmatter
In Deno with esm.sh
:
1import {frontmatter, frontmatterHtml} from 'https://esm.sh/micromark-extension-frontmatter@2'
In browsers with esm.sh
:
1<script type="module"> 2 import {frontmatter, frontmatterHtml} from 'https://esm.sh/micromark-extension-frontmatter@2?bundle' 3</script>
Say our module example.js
looks as follows:
1import {micromark} from 'micromark' 2import {frontmatter, frontmatterHtml} from 'micromark-extension-frontmatter' 3 4const output = micromark('---\na: b\n---\n# c', { 5 extensions: [frontmatter()], 6 htmlExtensions: [frontmatterHtml()] 7}) 8 9console.log(output)
…now running node example.js
yields:
1<h1>c</h1>
This package exports the identifiers frontmatter
,
frontmatterHtml
, and toMatters
.
There is no default export.
The export map supports the development
condition.
Run node --conditions development module.js
to get instrumented dev code.
Without this condition, production code is loaded.
frontmatter(options?)
Create an extension for micromark
to enable frontmatter syntax.
options
(Options
, default: ['yaml']
)
— configurationExtension for micromark
that can be passed in extensions
, to enable
frontmatter syntax (Extension
).
frontmatterHtml(options?)
Create an extension for micromark
to support frontmatter when serializing to
HTML.
👉 Note: this makes sure nothing is generated in the output HTML for frontmatter.
options
(Options
, default: ['yaml']
)
— configurationExtension for micromark
that can be passed in htmlExtensions
, to support
frontmatter when serializing to HTML
(HtmlExtension
).
toMatters(options?)
Simplify options by normalizing them to an array of matters.
options
(Options
, default: ['yaml']
)
— configurationList of matters (Array<Matter>
).
Info
Sequence (TypeScript type).
Depending on how this structure is used, it reflects a marker or a fence.
open
(string
)
— openingclose
(string
)
— closingMatter
Fields describing a kind of matter (TypeScript type).
👉 Note: using
anywhere
is a terrible idea. It’s called frontmatter, not matter-in-the-middle or so. This makes your markdown less portable.
👉 Note:
marker
andfence
are mutually exclusive. Ifmarker
is set,fence
must not be set, and vice versa.
type
(string
)
— node type to tokenize asmarker
(string
or Info
)
— character repeated 3 times, used as complete fencesfence
(string
or Info
)
— complete fencesanywhere
(boolean
, default: false
)
— whether matter can be found anywhere in the document, normally only
matter at the start of the document is recognizedOptions
Configuration (TypeScript type).
1type Options = Array<Matter | Preset> | Matter | Preset
Preset
Known name of a frontmatter style (TypeScript type).
'yaml'
— Matter
defined as {type: 'yaml', marker: '-'}
'toml'
— Matter
defined as {type: 'toml', marker: '+'}
1type Preset = 'toml' | 'yaml'
Here are a couple of example of different matter objects and what frontmatter they match.
To match frontmatter with the same opening and closing fence, namely three of
the same markers, use for example {type: 'yaml', marker: '-'}
, which matches:
1--- 2key: value 3---
To match frontmatter with different opening and closing fences, which each use
three different markers, use for example
{type: 'custom', marker: {open: '<', close: '>'}}
, which matches:
1<<< 2data 3>>>
To match frontmatter with the same opening and closing fences, which both use
the same custom string, use for example {type: 'custom', fence: '+=+=+=+'}
,
which matches:
1+=+=+=+ 2data 3+=+=+=+
To match frontmatter with different opening and closing fences, which each use
different custom strings, use for example
{type: 'json', fence: {open: '{', close: '}'}}
, which matches:
1{ 2 "key": "value" 3}
When authoring markdown with frontmatter, it’s recommended to use YAML frontmatter if possible. While YAML has some warts, it works in the most places, so using it guarantees the highest chance of portability.
In certain ecosystems, other flavors are widely used. For example, in the Rust ecosystem, TOML is often used. In such cases, using TOML is an okay choice.
When possible, do not use other types of frontmatter, and do not allow frontmatter anywhere.
Frontmatter does not relate to HTML elements. It is typically stripped, which is what these extensions do.
This package does not relate to CSS.
Frontmatter forms with the following BNF:
1frontmatter ::= fenceOpen *( eol *line ) eol fenceClose 2fenceOpen ::= sequenceOpen *spaceOrTab 3fenceClose ::= sequenceClose *spaceOrTab 4; Note: options can define custom sequences. 5sequenceOpen ::= 3"+" / 3"-" 6; Note: options can define custom sequences. 7; Restriction: `sequenceClose` must correspond to `sequenceOpen`. 8sequenceClose ::= 3"+" / 3"-" 9 10; Character groups for informational purposes. 11byte ::= %x00-FFFF 12spaceOrTab ::= "\t" / " " 13eol ::= "\n" / "\r" / "\r\n" 14line ::= byte - eol
Frontmatter can only occur once. It cannot occur in a container. It must have a closing fence. Like flow constructs, it must be followed by an eol (line ending) or eof (end of file).
This package is fully typed with TypeScript.
It exports the additional types Info
, Matter
,
Options
, Preset
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
micromark-extension-frontmatter@^2
, compatible with Node.js 16.
This package works with micromark
version 3
and later.
This package is safe.
remark-frontmatter
— remark plugin using this to support frontmattermdast-util-frontmatter
— mdast utility to support frontmatterSee 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More