Version 0.1.0
Configuration & Parsers
Updated 9 hr ago
Configure YAML/TOML frontmatter parsing, metadata field mappings, and custom third-party parser engines.
@m2d/frontmatter provides zero-dependency metadata parsing and extraction for markdown documents, translating frontmatter headers directly into Microsoft Word document properties.
🛠️ Options Reference
The frontmatterPlugin(options) factory accepts an optional configuration object:
export interface FrontmatterPluginOptions {
/**
* Custom parser function to override the built-in YAML/TOML parser.
* Useful when full YAML 1.2 or TOML specifications are required.
*/
parser?: (raw: string, type?: FrontmatterType) => FrontmatterData;
/**
* Custom transform function to map raw metadata to OpenXML document properties.
*/
transform?: (frontmatter: FrontmatterData, docxProps: IDocxProps) => void;
/**
* Automatically generate a standalone cover page from frontmatter metadata.
*/
coverPage?: boolean | CoverPageOptions;
/**
* Automatically generate a styled info-box / callout banner from frontmatter metadata.
*/
infoBox?: boolean | InfoBoxOptions;
}📄 Automated Cover Page
Generate a standalone title/cover page at the start of your DOCX document:
import { frontmatterPlugin } from "@m2d/frontmatter";
const plugin = frontmatterPlugin(undefined, {
coverPage: true, // or provide CoverPageOptions overrides
});When enabled, @m2d/frontmatter synthesizes:
- Title (
H1) fromfrontmatter.titleordocxProps.title - Subtitle / description in emphasis styling
- Thematic break divider
- Key metadata lines (Author, Organization, Date, Version)
- A page break before the body content, and automatically deduplicates any matching
H1in the document body.
📋 Metadata Info-Box / Callout
Generate a compact callout or table summarizing document metadata at the top of the body:
import { frontmatterPlugin } from "@m2d/frontmatter";
const plugin = frontmatterPlugin(undefined, {
infoBox: {
format: "blockquote", // "blockquote" (callout box) or "table"
position: "after-title", // "after-title" or "top"
header: "Document Information",
},
});🔌 Custom Parser Integration
To use standard parsers such as yaml or smol-toml:
import YAML from "yaml";
import { frontmatterPlugin } from "@m2d/frontmatter";
export const configuredFrontmatter = frontmatterPlugin({
parser: (raw, type) => {
if (type === "yaml") {
return YAML.parse(raw);
}
return {};
},
});