This filter program generates a Table of Contents (TOC) from Markdown files. Written in C with standard libraries, making it light, fast and highly portable across various systems.
Clone the repo:
git clone https://github.com/xuminic/markdown-toc-c
Build the program:
make
-
filtering from pipe:
cat README.md | md-tocThe TOC will be printed out in the console.
-
read from files:
md-toc README.mdThe TOC will be printed out in the console.
-
overwrite the TOC in the markdown files:
Before doing so, you need to add a pair of place mark to let
md-tocknow where to place the TOC. The place marks are HTML comments so they would be hidden from displaying.<!--toc--> <!--toc-->This README.md can be the example of where to set the place marks. Then using
-ooption to replace the old TOC:md-toc -o README1.md README2.md README3.mdmd-toccan batch process the markdown files. Each file would be updated with the new TOC.If there's no
<!--toc-->mark in the markdown file, the TOC will be saved at the beginning of the file.
-oaka--overwrite: update the markdown file with the TOC.-saka--show: show the markdown file with TOC in console, no overwrite.
Without option, the md-toc will show only the TOC part in the console,
not the TOC with the input file.