mdformat-toc
Mdformat plugin to generate table of contents
What it is and what it does
Mdformat-toc extends mdformat, a Markdown formatter, with the ability to automatically generate and update a table of contents. You mark a location in your Markdown file with an HTML comment (<!-- mdformat-toc start -->), then run mdformat, and the plugin generates a ToC listing the headings in your document at that location.
By default, the plugin creates HTML anchors for each heading so ToC links work across different Markdown renderers. You can configure which heading levels to include, disable anchor generation, and choose between GitHub and GitLab slug functions for link generation. The plugin is designed to work with mdformat's standard formatting workflow and requires only mdformat as a runtime dependency.
Use it for:
- Auto-generate and keep a table of contents synchronized in long Markdown documentation files.
- Maintain consistent heading-to-anchor mappings across GitHub and GitLab hosted Markdown.
- Integrate ToC generation into CI/CD pipelines that already use mdformat for Markdown formatting.
- Generate navigable ToCs in README files without manually updating links when headings change.
- Configure heading-level filtering to create ToCs that exclude top-level or deeply nested headings.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Mdformat-toc is an mdformat plugin that automatically generates and maintains a table of contents in Markdown files, with configurable heading levels and anchor generation.
Yes, if you use mdformat and need automated table-of-contents generation in Markdown files. The package is straightforward to install, has no security vulnerabilities, and works with current Python versions. The 303-day gap since last release suggests maintenance rather than active development, but the repository is not archived and the plugin remains functional for its intended use.
Install
mdformat-toc on PyPI
pip
pip install mdformat-tocuv
uv add mdformat-tocpoetry
poetry add mdformat-tocInstalling mdformat-toc
Before you install
Low friction install with a single runtime dependency on mdformat. The package is aging (303 days since last release) but the repository remains active and not archived, with support for current Python versions (3.9 through 3.14).
License in practice
MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute the package freely provided you retain the license notice.
Quickstart
pip install mdformat-toc
# Add to your Markdown file:
# <!-- mdformat-toc start -->
# Then run:
mdformat your_file.md
Requires mdformat to be installed; mdformat-toc works as a plugin that extends mdformat's formatting capabilities.
Verify before relying
- Whether the package is actively maintained or in maintenance-only mode given the 303-day gap since last release.
- Real-world compatibility with Markdown renderers other than GitHub and GitLab.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — mdformat |
| Maintenance | aging — 303 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 105,855/month — #12,675 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: mdformat_toc-0.5.0-py3-none-any.whl
Keywords: mdformat, markdown, commonmark, formatter
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
mdformat_mystmdformat-myst is an mdformat plugin that…
permissive · top 15,000 on PyPI
mdformatMdformat is a CommonMark-compliant command-line…
permissive · top 5,000 on PyPI
mdformat-blackA plugin for mdformat that automatically…
permissive · top 15,000 on PyPI
mdformat-ruffIntegrates ruff code formatting into mdformat…
permissive · top 15,000 on PyPI
mdformat-mkdocsAn mdformat plugin that formats Markdown for…
permissive · top 15,000 on PyPI
mdformat-gfmMdformat-gfm extends mdformat to format GitHub…
permissive · top 5,000 on PyPI
mdformat_tablesmdformat-tables is a plugin for mdformat that…
permissive · top 15,000 on PyPI
mdformat-frontmattermdformat-frontmatter is an mdformat plugin that…
permissive · top 5,000 on PyPI
tomli-wTomli-W serializes Python dictionaries to TOML…
permissive · top 1,000 on PyPI
markdown-pdfConverts markdown text to PDF files, with…
agpl · top 15,000 on PyPI