Skip to main content

PyPI md-toc version PyPI - License PyPI - Python Version Downloads Gitter Dependent repos (via libraries.io) Buy me a coffee

Automatically generate a compliant table of contents for a markdown file to improve document readability.

Video

https://asciinema.org/a/385730.png

Description

The table of contents (a.k.a: TOC) generated by this program is designed to work with several markdown parsers such as the ones used by GitHub and GitLab.

When used with the in-place option this script will write the TOC at the first occurrency of a marker. The default marker is <!--TOC-->, which, being an HTML comment, will result invisible after the markdown file has been translated.

By default titles up to three indentation levels (in HTML: h1, h2, h3) will be included in the TOC but the user can decide to keep all possible levels.

md_toc makes it is possible to generate ordered and unordered TOCs. In both cases each element of the TOC is by default a link to a paragraph in the web page. It is also possible to generate a non-linked version of the TOC.

If the user wants it, there is the possibility to ignore space indentations within the TOC and to skip an initial number of lines from the markdown file.

Rules for generating the TOC are determined by the selected markdown parser. md-toc aimes infact to be as conformant as possible in respect to each one of them. This was possible by studying the available documentations and by reverse engineering the source codes.

Documentation

http://frnmst.github.io/md-toc

Please read carefully the Markdown specification section of the documentation to learn how this program parsers markdown files and builds a correct output.

API examples

md-toc has a public API. This means for example that you can you easily build a TOC within another Python program. The easiest way to build one for a markdown file is:

>>> import md_toc
>>> f = open('foo.md')
>>> print(f.read(), end='')
# this
## is
## a
### foo
#### booo
### foo
## file

## bye

# bye
>>> print(md_toc.build_toc('foo.md'), end='')
- [this](#this)
  - [is](#is)
  - [a](#a)
    - [foo](#foo)
    - [foo](#foo-1)
  - [file](#file)
  - [bye](#bye)
- [bye](#bye-1)

CLI Helps

$ md_toc --help
$ md_toc github --help
$ md_toc redcarpet --help

License

Copyright (C) 2017-2020 frnmst (Franco Masotti) <franco.masotti@live.com>

md-toc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

md-toc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with md-toc. If not, see <http://www.gnu.org/licenses/>.

Trusted source

You can check the authenticity of new releases using my public key.

Instructions, sources and keys can be found at frnmst.gitlab.io/software.

Download files

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

Source Distribution

md_toc-7.1.0.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

md_toc-7.1.0-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file md_toc-7.1.0.tar.gz.

File metadata

  • Download URL: md_toc-7.1.0.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for md_toc-7.1.0.tar.gz
Algorithm Hash digest
SHA256 6f228a9b4cc8a1cf40894b0e569bbdfaf21b2c47a716b55723a582004ab35180
MD5 ca8424f3264792e3e2ab733de61154f5
BLAKE2b-256 10e4ef54fd05e5262226dab7602a2f310090321adc11b71a401eaed8546191ca

See more details on using hashes here.

File details

Details for the file md_toc-7.1.0-py3-none-any.whl.

File metadata

  • Download URL: md_toc-7.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for md_toc-7.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 112f283f88fe9dd086e5691ee9a6c70e8de963a8dd1bc639926d8006f5ca72b8
MD5 1f4ff9d31ec24a61ee0608d03f234e02
BLAKE2b-256 28002768b7815e35ee9d0ae49a9fa8bd48196bb2e8aca433cad530343d679f39

See more details on using hashes here.

Release history Release notifications | RSS feed

9.0.0

2 files

8.2.3

2 files

8.2.2

2 files

8.2.1

2 files

8.2.0

2 files

8.1.9

2 files

8.1.8

2 files

8.1.7

2 files

8.1.6

2 files

8.1.5

2 files

8.1.4

2 files

8.1.3

2 files

8.1.2

2 files

8.1.1

2 files

8.1.0

2 files

8.0.1

2 files

8.0.0

2 files

7.2.0

2 files

This release

7.1.0 This release

2 files

7.0.5

2 files

7.0.4

2 files

7.0.3

2 files

7.0.2

2 files

7.0.1

2 files

7.0.0

2 files

6.0.2

2 files

6.0.1

2 files

6.0.0

2 files

5.0.1

2 files

5.0.0

2 files

4.0.0

2 files

3.1.0

2 files

3.0.0

2 files

2.0.1

2 files

2.0.0

2 files

1.0.0

2 files

0.0.1

2 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