Skip to main content

Generate TOC for markdown files

Project description

tocs

PyPI

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.

How to install and use tocs

Prerequisites: Python 3.11.9+

Installation

pip install tocs

Update

pip install --upgrade tocs

Basic usage:

  • tocs input_file.md - Generate TOC for the file
  • tocs --depth 2 input_file.md - Limit the TOC generation to headers up to a specified depth
  • tocs --dry-run input_file.md - Preview TOC without modifying the file
  • tocs --help - Show usage instructions
  • tocs --version - Display version information

tocs example

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...

Development

  • 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tocs-1.0.5.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tocs-1.0.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file tocs-1.0.5.tar.gz.

File metadata

  • Download URL: tocs-1.0.5.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for tocs-1.0.5.tar.gz
Algorithm Hash digest
SHA256 6d6090545227624e7e23c3f4448af502b3b5fc30cfdab1e4ed77ecccba5c13c9
MD5 057f990b4fa172c6398691065e1fbda3
BLAKE2b-256 009979af8d8be672a7ce21f02f035c5d9a5ee834a3ccf84c25bc45707b0a80ef

See more details on using hashes here.

File details

Details for the file tocs-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: tocs-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for tocs-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e53183de9f25edff5a113c647bc6095f887fc4097c58058f3c500cf132fd4d75
MD5 690bdc952fc7f953c14a09d7258fab84
BLAKE2b-256 c669f081b8660a316e10c746e0ddd0703a71b25a0e592160e6bbe4462e6e1198

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page