Skip to main content

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:

  1. Intercepts lines containing [[_TOC_]] before they are parsed as paragraphs
  2. Creates a custom ado_toc token for these lines
  3. 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)

Source distribution for mdformat-ado-toc 0.0.1
File Size Uploaded
mdformat_ado_toc-0.0.1.tar.gz 33.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdformat-ado-toc 0.0.1
File Interpreter ABI Platform
mdformat_ado_toc-0.0.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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