Improved readme according to issue #36.

This commit is contained in:
Franco Masotti 2022-05-06 17:59:21 +02:00
parent ebc83fbb9f
commit b9208e64a0
Signed by: frnmst
GPG Key ID: 24116ED85666780A
2 changed files with 105 additions and 38 deletions

View File

@ -47,37 +47,105 @@ 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
-------------
GitHub and GitLab have introduced their version of the markdown TOC
after md-toc and similar tools were created:
https://docs.franco.net.eu.org/md-toc/
- in March 2021 GitHub added an interactive TOC button on the readme files of repositories which
works for markdown and other systems.
See:
https://github.blog/changelog/2021-04-13-table-of-contents-support-in-markdown-files/
- GitLab added an extension called ``Table of contents`` to
its `Gitlab Flavored Mardown`. See:
https://docs.gitlab.com/ee/user/markdown.html#table-of-contents
Please read carefully the `Markdown specification`_ section of the documentation
to learn how this program parsers markdown files and builds a correct output.
Features
--------
.. _Markdown specification: https://docs.franco.net.eu.org/md-toc/markdown_specification.html
- works offline
- edits file in place using a TOC marker (default ``<!--TOC-->``) or output to standard output
- selection of indentation level
- list indentation based on heading, which can optionally be disabled
- outputs an ordered or unordered TOC list
- creates anchor links to markdown headings by default or a plain list as alternative
- checks if heading level is coherent: this avoid creating an erroneous TOC. This feature can be disabled if needed
- skip any number lines before generating the TOC
- can read content from standard input
- handles multiple files at once
- selection of newline string
- selection of list marker
- supports GitHub, GitLab, Commonmark, Redcarpet and others
- `pre-commit <https://pre-commit.com/>`_ `hook <https://docs.franco.net.eu.org/md-toc/pre_commit_hook.html>`_
Examples
--------
You can use md-toc in your blog, documentation based on markdown, etc...
I use it in `my Jekyll-based blog <https://blog.franco.net.eu.org/>`_ along
with its `pre-commit hook <https://software.franco.net.eu.org/frnmst/blog/src/branch/master/.pre-commit-config.yaml>`_.
I also use it in most repositories where markdown README files are present.
Most markdown renderers do not provide a way to automatically generate a TOC so
md-toc is useful for this purpose.
A very common use case is this:
::
$ cat foo.md
# Table of contents
<!--TOC-->
# this
## is
## a
### foo
#### booo
### foo
## file
## bye
# bye
$ md_toc --in-place github --header-levels 6 foo.md # or: md_toc -p github -l6 foo.md
$ cat foo.md
# Table of contents
<!--TOC-->
- [Table of contents](#table-of-contents)
- [this](#this)
- [is](#is)
- [a](#a)
- [foo](#foo)
- [booo](#booo)
- [foo](#foo-1)
- [file](#file)
- [bye](#bye)
- [bye](#bye-1)
<!--TOC-->
# this
## is
## a
### foo
#### booo
### foo
## file
## bye
# bye
API examples
------------
@ -86,10 +154,8 @@ 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='')
@ -114,21 +180,31 @@ for a markdown file is:
- [bye](#bye)
- [bye](#bye-1)
.. _public API: https://docs.franco.net.eu.org/md-toc/api.html
Documentation
-------------
https://docs.franco.net.eu.org/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.
.. _Markdown specification: https://docs.franco.net.eu.org/md-toc/markdown_specification.html
CLI Helps
---------
::
$ md_toc --help
$ md_toc cmark --help
$ md_toc commonmarker --help
$ md_toc github --help
$ md_toc gitlab --help
$ md_toc goldmark --help
$ md_toc redcarpet --help
License
-------

View File

@ -121,12 +121,3 @@ Steps to add an unsupported markdown parser
4. Write or adapt an algorithm for that section.
5. Write unit tests for it.
6. Add the new parser to the CLI interface.
Curiosities
-----------
- GitLab added an extension called ``Table of contents`` to
its `Gitlab Flavored Mardown`. See:
https://docs.gitlab.com/ee/user/markdown.html#table-of-contents
- in March 2021 GitHub added an interactive TOC button on the readme files of repositories which works
works for markdown and other systems.