Socket
Book a DemoInstallSign in
Socket

tocs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tocs

Generate TOC for markdown files

pipPyPI
Version
1.0.5
Maintainers
1

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

Keywords

markdown

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts