An mdformat plugin to format YAML, TOML, or JSON front matter
Maintained. Last release 12 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install mdformat-front-mattersmdformat-front-matters
An mdformat plugin for normalizing YAML, TOML, and JSON front matter in CommonMark documents.
[!NOTE]
mdformat-frontmatterhas additional duplicate key detection, but did not support mdformat v1 (butler54/mdformat-frontmatter #37) nor TOML and JSON at the time (https://github.com/butler54/mdformat-frontmatter/issues/22#issuecomment-1815433725)Along with the 's', the extra dash is intentional to try to prevent typo errors.
Features
- Multi-format support: Handles YAML (
---), TOML (+++), and JSON ({...}) front matter - Automatic normalization: Formats front matter consistently (preserves key order by default, standardized indentation)
- Configurable sorting: Option to sort keys alphabetically with
--sort-front-matter - Error resilient: Preserves original content if parsing fails. Will error only if
strictmode is set - Zero configuration: Works out of the box with mdformat
Examples
YAML Front Matter:
---
title: My Document
date: 2024-01-01
tags:
- example
- demo
---
# Content
With --sort-front-matter, becomes:
---
date: 2024-01-01
tags:
- example
- demo
title: My Document
---
# Content
TOML Front Matter:
+++
title = "My Document"
date = 2024-01-01
tags = ["example", "demo"]
+++
# Content