mdformat-ado-toc
An mdformat plugin that preserves Azure DevOps' [[_TOC_]] directive.
mdformat normally escapes it to \[\[_TOC_\]\]. This plugin treats it
as a custom block and renders it back verbatim.
Problem
Azure DevOps wikis use [[_TOC_]] to generate a table of contents. However, when formatting markdown files with mdformat, the brackets get escaped to \[\[_TOC_\]\], which breaks the TOC functionality.
Solution
This plugin registers a custom parser extension that recognizes [[_TOC_]] as a special block element and preserves it without escaping during formatting.
Install
pip install mdformat-ado-toc
# or from source
pip install -e .
Usage
Command Line
mdformat document.md --extensions ado_toc
Python API
import mdformat
text = """
# My Document
[[_TOC_]]
## Section 1
Content here.
"""
formatted = mdformat.text(text, extensions=["ado_toc"])
print(formatted) # [[_TOC_]] is preserved!
Features
- ✅ Preserves
[[_TOC_]]without escaping brackets - ✅ Handles surrounding whitespace correctly
- ✅ Supports multiple TOC markers in one document
- ✅ Works correctly when mixed with other markdown content
- ✅ Uses Python type hints and modern Python syntax
Testing
pytest tests/test_plugin.py -v
How It Works
The plugin implements a custom markdown-it parser rule that:
- Intercepts lines containing
[[_TOC_]]before they are parsed as paragraphs - Creates a custom
ado_toctoken for these lines - Renders the token back as the literal string
[[_TOC_]]without escaping
License
MIT
Metadata
Release files for mdformat-ado-toc 0.0.1
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 | Actions |
|---|---|---|---|---|
| mdformat_ado_toc-0.0.1.tar.gz | 33.5 kB | Without provenance | Details for mdformat_ado_toc-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mdformat_ado_toc-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for mdformat_ado_toc-0.0.1-py3-none-any.whl |
Total release size: 37.8 kB
Release files / mdformat_ado_toc-0.0.1.tar.gz
| Download URL | mdformat_ado_toc-0.0.1.tar.gz |
|---|---|
| Size | 33.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e986f1b489b557e11dba3ea06cca74f173176dd602190965e18dbee5a914792
|
|
BLAKE2b-256 checksum How to use checksums |
ea7857df3e03ab4e959196250c16fcdc800ed0632c567f890b7cd047a2d40dd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / mdformat_ado_toc-0.0.1-py3-none-any.whl
| Download URL | mdformat_ado_toc-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd11e93db19cdb783ffee7400a636c397831285fa6079c7247de3b2ba3b2feca
|
|
BLAKE2b-256 checksum How to use checksums |
2c5668b8b01b3a5fb3aeeb9605eea8ba0b8e29b39139ccfe9bd40c7d9e5dd85d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for mdformat-ado-toc 0.0.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.