Remark Read Frontmatter is a Remark plugin written in TypeScript with native for YAML and and TOML frontmatters. No option is required.
The plugin parse the extracted frontmatter object by remark-frontmatter
and insert its properties in the vfile data
object.
Place this plugins after remark-frontmatter
and before remark-rehype
.
Beside the file extension, the code example is identical in JavaScript and TypeScript.
import assert from "assert";
import { unified } from "unified";
import parseMarkdown from "remark-parse";
import remark2rehype from "remark-rehype";
import html from "rehype-stringify";
import extractFrontmatter from "remark-frontmatter";
// Remark Read Frontmatter import
import pluginParseFrontmatter from "remark-read-frontmatter";
const { data } = unified()
.use(parseMarkdown)
.use(extractFrontmatter, ["yaml"])
.use(pluginParseFrontmatter)
.use(remark2rehype)
.use(html)
.processSync(
`
---
title: Article
lang: fr
---
`.trim(),
);
// Output validation
assert.deepEqual(data, {
title: "Article",
lang: "fr",
});
property
, string, defaultundefined
The property in vfile.data where to assign the frontmatter object. The default behavior merge the VFile data object with the frontmatter object.override
, boolean, defaultfalse
Override the VFile property (data
by default) instead of merging its value object.