tocs is a simple CLI application written in Python that generates the table of contents (TOC) section for markdown files.
As a person who loves to write personal technical notes in markdown files, I needed something simple to use.
Prerequisites: Python 3.11.9+
pip install tocspip install --upgrade tocstocs input_file.md- Generate TOC for the filetocs --depth 2 input_file.md- Limit the TOC generation to headers up to a specified depthtocs --dry-run input_file.md- Preview TOC without modifying the filetocs --help- Show usage instructionstocs --version- Display version information
Given the following markdown file input_file.md:
<!-- init-tocs -->
<!-- end-tocs -->
# header 1
Lorem ipsum dolor sit amet...
## header 2
Lorem ipsum dolor sit amet...
### header 3
Lorem ipsum dolor sit amet...Run tocs input_file.md and here's the output:
<!-- init-tocs -->
- [header 1](#header-1)
- [header 2](#header-2)
- [header 3](#header-3)
<!-- end-tocs -->
# header 1
Lorem ipsum dolor sit amet...
## header 2
Lorem ipsum dolor sit amet...
### header 3
Lorem ipsum dolor sit amet...- create venv:
python -m venv .venv - activate venv:
source .venv/bin/activate - install project and dependencies (editable mode):
pip install -e .[dev] - deactivate venv:
deactivate