MDFormat plugin that preserves Azure DevOps [[_TOC_]] directive
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdformat_ado_toc-0.0.1.tar.gz.
File metadata
- Download URL: mdformat_ado_toc-0.0.1.tar.gz
- Upload date:
- Size: 33.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e986f1b489b557e11dba3ea06cca74f173176dd602190965e18dbee5a914792
|
|
| MD5 |
1fbe275a54a991576427241cfec2a0a4
|
|
| BLAKE2b-256 |
ea7857df3e03ab4e959196250c16fcdc800ed0632c567f890b7cd047a2d40dd2
|
File details
Details for the file mdformat_ado_toc-0.0.1-py3-none-any.whl.
File metadata
- Download URL: mdformat_ado_toc-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd11e93db19cdb783ffee7400a636c397831285fa6079c7247de3b2ba3b2feca
|
|
| MD5 |
38156e6e4124442d126a26b918886c65
|
|
| BLAKE2b-256 |
2c5668b8b01b3a5fb3aeeb9605eea8ba0b8e29b39139ccfe9bd40c7d9e5dd85d
|