Mdformat plugin to generate table of contents
Project description
mdformat-toc
Mdformat plugin to generate a table of contents
Table of Contents generated with mdformat-toc
Description
Mdformat-toc is an mdformat plugin that adds mdformat the capability to auto-generate a table of contents (ToC). The ToC is generated in a user-specified location in the Markdown file.
Mdformat-toc, by default, creates an HTML anchor for each heading listed in the ToC. ToC links should therefore be compatible with any well-behaved Markdown renderer (including GitHub and GitLab).
HTML anchor generation can be disabled, in which case a user should configure a slug function that is compatible with the Markdown renderer used (GitHub and GitLab slug functions are currently supported).
Install
pip install mdformat-toc
Usage
Add the following line to your Markdown file. A ToC will be generated in the location indicated by it.
<!-- mdformat-toc start -->
After adding the indicator line, simply run
mdformat <filename>
and mdformat will generate a ToC.
Configuration
Arguments can be added to the indicator line to alter how the ToC is generated. An indicator line with the default options would look like:
<!-- mdformat-toc start --slug=github --maxlevel=6 --minlevel=1 -->
Placing more than one indicator lines in a document is currently not supported.
Minimum and maximum heading levels
A user can configure a range of heading levels to be included in the ToC (and to be "anchored"). For instance, the following configuration will only list 2nd, 3rd and 4th level headings in the ToC:
<!-- mdformat-toc start --minlevel=2 --maxlevel=4 -->
Disabling anchor generation
By default, an HTML anchor is appended to each heading. For instance, the following heading
# Some title
might be formatted as
# Some title<a name="some-title"></a>
This ensures that ToC links do not rely on a Markdown renderer to create HTML anchors, and makes the links universally compatible.
ToC links are by default compatible with the anchors generated by GitHub's Markdown renderer. If your Markdown is only hosted on GitHub, you can disable mdformat-toc's HTML anchor generation:
<!-- mdformat-toc start --no-anchors -->
Changing the slug function
By default, the ToC links are GitHub compatible, even without anchors being generated (via the --no-anchors
flag).
If you are using GitLab,
and have disabled anchor generation,
you will want to add a --slug=gitlab
argument:
<!-- mdformat-toc start --slug=gitlab --no-anchors -->
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
File details
Details for the file mdformat-toc-0.1.0.tar.gz
.
File metadata
- Download URL: mdformat-toc-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.7.9 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 174813607f0196d2ca5999946a46a9bf98b76620868974ef0e36283f8817ab77 |
|
MD5 | ed3e722d96fd9cb21836196f9b8ce61f |
|
BLAKE2b-256 | 8a0caa513201c0f953cfaf4e1853744fc82700f2be8934f4e4f8ed9ecb8a99af |
Provenance
File details
Details for the file mdformat_toc-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: mdformat_toc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.7.9 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9896197210af15492680c12f03a5b22026c77ed7b1397f2324b13e28c1e35166 |
|
MD5 | 16e1be40c4e8f94430e7edeb77db087e |
|
BLAKE2b-256 | 072834c38a2bbbbd41e57cd746960498d31de5c2f4f1f26ffe06843276d568d7 |