Skip to main content

mdformat-front-matters

Build Status PyPI version

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 strict mode 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: 1.0.0
    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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdformat-front-matters 2.1.0
File Size Uploaded Provenance Actions
mdformat_front_matters-2.1.0.tar.gz 13.9 kB With provenance Details for mdformat_front_matters-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdformat-front-matters 2.1.0
File Interpreter ABI Platform Actions
mdformat_front_matters-2.1.0-py3-none-any.whl Python 3 none any Details for mdformat_front_matters-2.1.0-py3-none-any.whl

Total release size: 27.5 kB

Release files / mdformat_front_matters-2.1.0.tar.gz

Download URL mdformat_front_matters-2.1.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7328d0987912e445aebb21e06a3ab36e2b961b9fa033956b75a4a61526a7124b
BLAKE2b-256 checksum
How to use checksums
c9340a3e420ddb964e9d3424798a74594266d87754f02f4097a0a509a0f55bf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 2, 2026.

Transparency log

Release files / mdformat_front_matters-2.1.0-py3-none-any.whl

Download URL mdformat_front_matters-2.1.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fb7bedf415e97d39764d2d34aeb7460897c845d59d6911dbfe48dfd2f7de5bd
BLAKE2b-256 checksum
How to use checksums
4378e8b84d3618d59117ba9498c2b367f801aeb62a67e387bb9126faeac1381a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 2, 2026.

Transparency log

Security for mdformat-front-matters 2.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mdformat_front_matters-2.1.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 2, 2026.

Transparency log

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page