frontmatter-md
v1.0.3
Published
Lightweight YAML frontmatter parser for Markdown files.
Maintainers
Readme
frontmatter-md
Lightweight YAML frontmatter parser for Markdown files.
The package extracts metadata written at the beginning of a Markdown file between --- delimiters and returns the remaining document content.
Do you have questions or want to receive notifications about important changes or new features in my repositories? Join my Discord server! If you do not use Discord, you can also open an issue on GitHub.
If you like this repository, leave a star ⭐. Thank you!
Installation
npm install frontmatter-mdNode.js usage
Markdown
---
title: "Hello World"
description: Simple post showing supported data types
author: Sefinek
order: 3
rating: 4.5
draft: false
featured: true
tags: [markdown, frontmatter, parser]
categories:
- JavaScript
- Markdown
- Tools
---
# Heading
The document content is returned separately, without the frontmatter block.Example
const parseFrontmatter = require('frontmatter-md');
const { data, content } = parseFrontmatter(markdown);Output
{
"data": {
"title": "Hello World",
"description": "Simple post showing supported data types",
"author": "Sefinek",
"order": 3,
"rating": 4.5,
"draft": false,
"featured": true,
"tags": ["markdown", "frontmatter", "parser"],
"categories": ["JavaScript", "Markdown", "Tools"]
},
"content": "# Heading\nThe document content is returned separately, without the frontmatter block."
}Browser usage
URL
https://cdn.jsdelivr.net/npm/frontmatter-md@1/dist/mdFrontmatter.min.js
Example
<script src="https://cdn.jsdelivr.net/npm/frontmatter-md@1/dist/mdFrontmatter.min.js"></script>
<script>
const markdown = `---
title: Browser example
tags: [html, browser, markdown]
draft: false
---
# Browser example
Parsed directly in the browser.`;
const { data, content } = mdFrontmatter(markdown);
console.log(data);
console.log(content);
</script>Supported values
- strings, including quoted strings
- numbers
trueandfalsevalues- YAML lists
- inline arrays, e.g.
[foo, bar, baz] - comments and empty lines inside the frontmatter block
API
const result = parseFrontmatter(markdown);The function returns an object:
{
data: {}, // Metadata from frontmatter
content: '' // Markdown content without frontmatter
}If the text does not contain valid frontmatter, data will be an empty object and content will remain unchanged.
Development
npm test
npm run lint
npm run buildMIT License
Copyright © 2026 Sefinek
