Skip to main content

A table of contents (TOC) plugin for markdown-it-py

Project description

mdit-py-toc

A table of contents (TOC) plugin for markdown-it-py based on markdown-it-toc-done-right.

Installation

Install using poetry

Because mdit-py-toc is a plugin, you most likely need a tool to handle Python package dependencies and Python environments. Therefore we strongly recommend using poetry.

You can install the latest stable release and add it as a dependency for your current project using poetry

poetry add mdit-py-toc

Install using pip

[!NOTE] The pip install command does no longer work out-of-the-box in newer distributions like Ubuntu >= 23.04 because of PEP 668.

You can install the latest stable release from the Python Package Index (pypi) using pip

python -m pip install mdit-py-toc

Options

Name Description Default
pattern The pattern serving as the TOC placeholder in your markdown r"^(\[TOC\]")
level Heading level to apply anchors on or iterable of selected levels (1, 2)
list_type Type of list ("ul" for unordered, "ol" for ordered) "ul"
slug_func Function to convert heading title text to id slugs for link references mdit_py_toc.slugify

Usage

mdit-py-toc works best in conjunction with the anchors plugin.

from markdown_it import MarkdownIt
from mdit_py_plugins.anchors import anchors_plugin
from mdit_py_toc import toc_plugin, slugify

md = (
  MarkdownIt()
  .use(anchors_plugin, permalink=True, slug_func=slugify)
  .use(toc_plugin, list_type="ol")
)
markdown = """
# A Page

[TOC]

## Section 1

## Section 2
"""
html = md.render(markdown)

Creates the following HTML output

<h1 id="a-page">A Page <a class="header-anchor" href="#a-page">¶</a></h1>
<nav>
<ol>
<li><a href="#a-page">A Page </a><ol>
<li><a href="#section-1">Section 1 </a></li>
<li><a href="#section-2">Section 2 </a></li>
</ol></li>
</ol></nav>
<h2 id="section-1">Section 1 <a class="header-anchor" href="#section-1">¶</a></h2>
<h2 id="section-2">Section 2 <a class="header-anchor" href="#section-2">¶</a></h2>

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

mdit_py_toc-1.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

mdit_py_toc-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file mdit_py_toc-1.0.0.tar.gz.

File metadata

  • Download URL: mdit_py_toc-1.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for mdit_py_toc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7a7f5f548185f8d24dacb60032d8606728ded59bc72326b3c4765ae00978fa7a
MD5 b20b5e39e361f0c3d1fb30d12374ba34
BLAKE2b-256 5a662b87cd98820aa3794717748b9b0f042bb63918622f5551f3522edce1f6e7

See more details on using hashes here.

Provenance

File details

Details for the file mdit_py_toc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mdit_py_toc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for mdit_py_toc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f09c2b1d0068daccde94e712d0343cb43699514be05a7f492124df87ac28c7c1
MD5 2d2bb6ca030c8be16e0e43f019c0092c
BLAKE2b-256 1c9379ebb659e7f3e874ece4021fb4786e0e826241f4c93cdc9da555014eeb7b

See more details on using hashes here.

Provenance

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