Skip to main content

Mdformat plugin to generate table of contents

Reason this release was yanked:

uses external private API

Project description

Build Status PyPI version

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 GitLab's renderer).

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

Mdformat-toc defaults to using GitHub's slug function.

If your Markdown is not hosted on GitHub you may want to use GitLab's slug function instead:

<!-- mdformat-toc start --slug=gitlab --no-anchors -->

NOTE: Unlike GitLab, GitHub requires using its own slug function in order for ToC links to work expectedly. Creating HTML anchors and using a non-GitHub slug function is not GitHub compatible because GitHub's Markdown renderer modifies the HTML anchors mdformat-toc creates. The default configuration (GitHub slug function and anchor generation) is the only configuration cross-compatible with GitHub and GitLab.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdformat-toc-0.2.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

mdformat_toc-0.2.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file mdformat-toc-0.2.2.tar.gz.

File metadata

  • Download URL: mdformat-toc-0.2.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.10 Linux/5.4.0-1041-azure

File hashes

Hashes for mdformat-toc-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4c6db5f6190003c332d0c63a357a92f66e58ea4203b401269d08d7ca065e5236
MD5 59f236fb2bcc89b81d16dd2e4f5ce774
BLAKE2b-256 e5b9a96e859e97433ea20ce6c239928477c90ad5b2844137c6b9ce60be832b1a

See more details on using hashes here.

File details

Details for the file mdformat_toc-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: mdformat_toc-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.10 Linux/5.4.0-1041-azure

File hashes

Hashes for mdformat_toc-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1bf6de1335a02acc0b3a26d93e612458d9d4eac7e0afc8096770f5cba0f489b
MD5 cacf9a5e6c605b6d0a841880581f2605
BLAKE2b-256 7f88f20e2f236ab6d960f738321299ba39feadfff776239c463e0c266ef00f0b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page