Skip to main content

PyPI md-toc version PyPI - License PyPI - Python Version Downloads

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

Description

The table of contents generated by this program is designed to work with several markdown parsers such as the one used by GitHub and GitLab.

When used with the in-place option this script will write the table of contents at the first occurrency of a marker. The default marker is [](TOC) which will result as invisible when reading the parsed markdown file.

By default, titles up to three indentation levels (in HTML: h1, h2, h3) will be included in the table of contents.

As a final remark, it is possible to generate an ordered and an unordered table of contents. In both cases, each element of the toc is by default a clickable link to a paragraph in the page. It is also possible to generate non-linked version of the TOC.

Rules for generating the table of contents are determined by the selected markdown parser. md_toc aimes to be as conformant as possible in respect to each one of them.

Video

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

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.

Conventions

  • PEP 8.

  • 4 space indentation.

Helps

usage: md_toc [-h] [-p] [-l] [-i] [-m TOC_MARKER] [-v]
              [FILE_NAME [FILE_NAME ...]]
              {github,cmark,gitlab,commonmarker,redcarpet} ...

Markdown Table Of Contents: Automatically generate a compliant table
of contents for a markdown file to improve document readability.

positional arguments:
  FILE_NAME             the I/O file name

optional arguments:
  -h, --help            show this help message and exit
  -p, --in-place        overwrite the input file
  -l, --no-links        avoids adding links to the corresponding content
  -i, --no-indentation  avoids adding indentations to the corresponding
                        content
  -m TOC_MARKER, --toc-marker TOC_MARKER
                        set the string to be used as the marker for
                        positioning the table of contents. Defaults to [](TOC)
  -v, --version         show program's version number and exit

markdown parser:
  {github,cmark,gitlab,commonmarker,redcarpet}

Return values: 0 OK, 1 Error, 2 Invalid command

Copyright (C) 2018-2019 Franco Masotti, frnmst
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
usage: md_toc [FILE_NAME [FILE_NAME ...]] github [-h] [-u [{-,+,*}] | -o
                                                 [{.,)}]]
                                                 [-l [{1,2,3,4,5,6}]]

Use Commonmark rules to generate an output. If no option is selected, the
default output will be an unordered list with the respective default values as
listed below

optional arguments:
  -h, --help            show this help message and exit
  -u [{-,+,*}], --unordered-list-marker [{-,+,*}]
                        set the marker and enables unordered list. Defaults to
                        -
  -o [{.,)}], --ordered-list-marker [{.,)}]
                        set the marker and enables ordered lists. Defaults to
                        .
  -l [{1,2,3,4,5,6}], --header-levels [{1,2,3,4,5,6}]
                        set the maximum level of headers to be considered as
                        part of the TOC. Defaults to 3
usage: md_toc [FILE_NAME [FILE_NAME ...]] redcarpet [-h] [-u [{-,+,*}] |
                                                    -o [{.}]]
                                                    [-l [{1,2,3,4,5,6}]]

Use Redcarpet rules to generate an output. If no option is selected, the
default output will be an unordered list with the respective default values as
listed below. Gitlab rules are the same as Redcarpet except that conflicts are
avoided with duplicate headers.

optional arguments:
  -h, --help            show this help message and exit
  -u [{-,+,*}], --unordered-list-marker [{-,+,*}]
                        set the marker and enables unordered list. Defaults to
                        -
  -o [{.}], --ordered-list-marker [{.}]
                        set the marker and enables ordered lists. Defaults to
                        .
  -l [{1,2,3,4,5,6}], --header-levels [{1,2,3,4,5,6}]
                        set the maximum level of headers to be considered as
                        part of the TOC. Defaults to 3

TODO and FIXME

grep -e TODO -e FIXME -n */*.py

License

Copyright (C) 2017-2019 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/>.

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-3.0.0.tar.gz (26.6 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-3.0.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md_toc-3.0.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for md_toc-3.0.0.tar.gz
Algorithm Hash digest
SHA256 80b6767099852a8c7031f6276753dcccc70bf2b59a35695004fb535459315c2e
MD5 f5347075db53e48b218972117d9ea204
BLAKE2b-256 c6e7d9d3e5c57b7b707a2323b4a243f6e6a5de5a8b1205be7752492aab632377

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md_toc-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for md_toc-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32ede9d83975fa8b86768dd38535142ea152ed22c117ad9baf6eda4dffeef577
MD5 706fd215dc21aa1d3c2d18375c75f4a6
BLAKE2b-256 ae4ccfcbf571fd47902f0fdaa698076c33783a386f3366309ec5167a71952e2e

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

7.1.0

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

This release

3.0.0 This release

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