Package: md-toc
Markdown Table Of ContentsAutomatically generate and add an accurate table of contents to markdown files.Markdown Table Of ContentsVideoDescriptionFeaturesExamplesAPI examplesDocumentationCLI HelpsExtrasHTML outputLicenseChangelog and trusted sourceSupport this projectVideoDescriptionThe 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.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.GitHub and GitLab have introduced their version of the markdown TOC
after md-toc and similar tools were created:in March 2021 GitHub added aninteractive TOC buttonat the top-left of readme files. This system works for markdown and othersGitLab added anextensioncalledTable of contentsto its Gitlab Flavored MardownFeaturesworks offlineedits file in place using a TOC marker (default<!--TOC-->) or
output to standard outputmaximum heading level selection (1 to 6)list indentation based on heading, which can optionally be disabledoutputs an ordered or unordered TOC list with list marker selectioncreates anchor links to markdown headings by default or a plain list
as alternativechecks if heading level is coherent: this avoid creating an
erroneous TOC. This feature can be disabled if neededskip any number lines before generating the TOCcan read content from standard inputhandles multiple files at onceselection of newline stringcheck if there is difference between existing TOC in file and newly generated
onesupports GitHub, GitLab, Commonmark, Redcarpet and otherspre-commitmd-tochookAnd more! See thefeature comparison tableExamplesYou can use md-toc in your blog, documentation based on markdown, GitHub pages,
markdown files in Nextcloud, etc...I use it inmy Jekyll-based blogalong with itspre-commit hook.
I also use it in most repositories whereREADME.mdfiles 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:$catfoo.md# Table of contents<!--TOC--># this## is## a### foo#### booo### foo## file## bye# bye$md_toc--in-placegithub--header-levels6foo.md# or: md_toc -p github -l6 foo.md$catfoo.md# Table of contents<!--TOC-->

-[Tableofcontents](#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# byeAPI examplesmd-toc has apublic 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:>>>importmd_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)You can also write the TOC in place:>>>importmd_toc>>>f=open('foo.md')>>>print(f.read(),end='')# Table of contents<!--TOC--># this## is## a### foo#### booo### foo## fileTest## bye# bye>>>toc=md_toc.build_toc('foo.md')>>>md_toc.write_string_on_file_between_markers('foo.md',toc,'<!--TOC-->')>>>f=open('foo.md')>>>print(f.read(),end='')# Table of contents<!--TOC-->-[Tableofcontents](#table-of-contents)-[this](#this)-[is](#is)-[a](#a)-[foo](#foo)-[foo](#foo-1)-[file](#file)-[bye](#bye)-[bye](#bye-1)<!--TOC--># this## is## a### foo#### booo### foo## fileTest## bye# byeDocumentationhttps://docs.franco.net.eu.org/md-toc/Please read theMarkdown specificationsection of the documentation to learn how this program parsers markdown
files and builds a correct output.CLI Helps$md_toc--help
$md_toccmark--help
$md_toccommonmarker--help
$md_tocgithub--help
$md_tocgitlab--help
$md_tocgoldmark--help
$md_tocredcarpet--helpExtrasHTML outputIf you usePandocyou can
generate an HTML output starting from a markdown file. You can do something
like:pandoc--from=commonmark--to=html-oa.htmlREADME.mdLicenseCopyright (C) 2017-2024Franco Masottimd-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, seehttp://www.gnu.org/licenses/.Changelog and trusted sourceYou can check the authenticity of new releases using my public key.Changelogs, instructions, sources and keys can be found atblog.franco.net.eu.org/software/#md-toc.Support this projectBuy Me a CoffeeLiberapayBitcoin:bc1qnkflazapw3hjupawj0lm39dh9xt88s7zal5mwuMonero:84KHWDTd9hbPyGwikk33Qp5GW7o7zRwPb8kJ6u93zs4sNMpDSnM5ZTWVnUp2cudRYNT6rNqctnMQ9NbUewbj7MzCBUcrQEYDogecoin:DMB5h2GhHiTNW7EcmDnqkYpKs6Da2wK3zPVertcoin:vtc1qd8n3jvkd2vwrr6cpejkd9wavp4ld6xfu9hkhh0