mdformat-front-matters
An mdformat plugin for normalizing YAML, TOML, and JSON front matter in CommonMark documents.
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
JSON Front Matter:
{
"title": "My Document",
"date": "2024-01-01",
"tags": ["example", "demo"]
}
# Content
mdformat Usage
Add this package wherever you use mdformat and the plugin will be auto-recognized. No additional configuration necessary. See additional information on mdformat plugins here
pre-commit / prek
repos:
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.19
hooks:
- id: mdformat
additional_dependencies:
- mdformat-front-matters
uvx
uvx --with mdformat-front-matters mdformat
Or with pipx:
pipx install mdformat
pipx inject mdformat mdformat-front-matters
Configuration Options
Key Sorting
By default, front matter keys preserve their original order. To sort keys alphabetically for consistency, use the --sort-front-matter flag.
# Default behavior - preserves original key order
mdformat document.md
# Sort keys alphabetically
mdformat document.md --sort-front-matter
Strict Mode
Enable strict mode to fail on invalid front matter instead of preserving it. Useful for CI/CD pipelines.
mdformat document.md --strict-front-matter
In strict mode:
- Invalid front matter raises an error
- Front matter without valid key-value pairs raises an error
- Ensures your documents have correctly formatted metadata
Example usage in pre-commit:
repos:
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.19
hooks:
- id: mdformat
args: [--strict-front-matter]
additional_dependencies:
- mdformat-front-matters
HTML Rendering
To hide Front Matter from generated HTML output, front_matters_plugin can be imported from mdit_plugins. For more guidance on MarkdownIt, see the docs: https://markdown-it-py.readthedocs.io/en/latest/using.html#the-parser
from markdown_it import MarkdownIt
from mdformat_front_matters.mdit_plugins import front_matters_plugin
md = MarkdownIt()
md.use(front_matters_plugin)
text = """
+++
title = "Example"
draft = false
+++
# Example
"""
md.render(text)
# <h1>Example</h1>
-->
Contributing
See CONTRIBUTING.md
Metadata
Release files for mdformat-front-matters 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mdformat_front_matters-2.0.0.tar.gz | 12.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mdformat_front_matters-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.0 kB
Release files / mdformat_front_matters-2.0.0.tar.gz
| Download URL | mdformat_front_matters-2.0.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46efabe93707699120c67d4b33b51fdb4cfe0e040acfb0f8212eb33c9a3e8a9a
|
|
BLAKE2b-256 checksum How to use checksums |
2c53008805510d3006d9aec6c602fa40305750cb96daba8ea9abae477149909b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.
Transparency logRelease files / mdformat_front_matters-2.0.0-py3-none-any.whl
| Download URL | mdformat_front_matters-2.0.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ea92d23d1e9427fe6548b9044e5fbf7bcf6c217941f1a9442e0efd8b0a76e61
|
|
BLAKE2b-256 checksum How to use checksums |
00054c197c000dab41f1f58290221a4c02bd57804ff42e9374d3dd0f5408aa40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.
Transparency logSecurity for mdformat-front-matters 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mdformat_front_matters-2.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.