Expand description
Python-Markdown anchor generation (used by MkDocs)
This module implements the exact slugify algorithm from Python-Markdown’s
toc extension, which is the default used by MkDocs.
Algorithm (from markdown/extensions/toc.py):
- NFKD Unicode normalization, then encode to ASCII (ignore errors)
- Remove all characters except
\w,\s, and- - Lowercase and strip leading/trailing whitespace
- Collapse consecutive hyphens and whitespace into a single separator
Verified against Python-Markdown 3.x via:
uv run --with markdown python3 -c "
from markdown.extensions.toc import slugify
print(slugify('Your Heading', '-'))
"Functions§
- heading_
to_ fragment - Generate a Python-Markdown style anchor fragment from heading text.