| Crates.io | markdown-frontmatter |
| lib.rs | markdown-frontmatter |
| version | 0.4.0 |
| created_at | 2025-07-30 16:39:31.253702+00 |
| updated_at | 2025-08-03 06:18:50.967511+00 |
| description | A type-safe markdown frontmatter parser |
| homepage | |
| repository | https://github.com/imbolc/markdown-frontmatter |
| max_upload_size | |
| id | 1773785 |
| size | 41,783 |
A type-safe parser for Markdown frontmatter.
This crate provides a simple and efficient way to split and parse frontmatter from Markdown documents.
The crate supports the following frontmatter formats and their corresponding delimiters:
{ on the first line and } on a closing line. The
enclosed JSON content must be indented to be parsed correctly.
{
"title": "JSON Frontmatter"
}
+++ on opening and closing lines.
+++
title = "TOML Frontmatter"
+++
--- on opening and closing lines.
---
title: YAML Frontmatter
---
Add the crate to your dependencies:
cargo add markdown-frontmatter
#[derive(serde::Deserialize)]
struct Frontmatter {
title: String,
}
let doc = r#"---
title: Hello
---
World"#;
let (frontmatter, body) = markdown_frontmatter::parse::<Frontmatter>(doc).unwrap();
assert_eq!(frontmatter.title, "Hello");
assert_eq!(body, "World");
If a document does not contain a frontmatter, it is treated as if it has an empty one. This allows to make frontmatter fully optional by using only optional fields, e.g.
#[derive(serde::Deserialize)]
struct Frontmatter {
title: Option<String>,
}
let doc = "Hello";
let (frontmatter, body) = markdown_frontmatter::parse::<Frontmatter>(doc).unwrap();
assert!(frontmatter.title.is_none());
assert_eq!(body, "Hello");
This crate has the following Cargo features:
json: Enables JSON frontmatter parsing.toml: Enables TOML frontmatter parsing.yaml: Enables YAML frontmatter parsing.By default, no features are enabled.
Before submitting a pull request, please run the .pre-commit.sh script:
./.pre-commit.sh
This project is licensed under the MIT license.