Skip to main content

toc

Generate a table of contents from the comments of a file

Example table of contents generated by toc

What is it?

toc is a CLI utility to generates Table of Contents of text files. It aims to be the tree for the contents of a file, instead of a directory.

toc comes with native support for Markdown, AsciiDoc, reStructuredText, HTML and many more. It can support any language through a special kind of comments.1

Why should I use it?

Few reasons that you may consider:

  • it can make your files and code base understandable in seconds, to you and others
  • you can jump directly to the section you need to edit, because you see where it's located
  • it makes you reflect about the structure of your file

How does it work?

For markup languages such as Markdown, AsciiDoc, reStructuredText and HTML, no changes are needed. For other languages (e.g. C), write some comments representing the different sections of a file.1 After this, run toc on that file to turn those comments into a table of contents.

Comments are structured in this way:

Syntax of comments used to generate table of contents

By running toc file.c, you will read the table of contents of that file:

Toc generated from syntax comments

How can I install it?

First, you need Python installed in your system.

Then, you can install toc by running:

pip install tableofcontents

If you are using Arch or Manjaro Linux, you can install toc directly from the AUR.

You should now be able to run toc -h to display a list of parameter you can use.

See USAGE.md for step-by-step explanations of different features, and a list of languages supported natively or that need special attention (e.g. CSS)

How can I contribute?

See CONTRIBUTING.md

What has changed from previous versions?

See CHANGELOG.md

  1. For examples of valid and invalid comments, see https://regex101.com/r/ngzZXN/2 ↩ ↩2

Metadata

Release files for tableofcontents 2.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tableofcontents 2.7.4
File Size Uploaded Provenance Actions
tableofcontents-2.7.4.tar.gz 28.2 kB Without provenance Details for tableofcontents-2.7.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tableofcontents 2.7.4
File Interpreter ABI Platform Actions
tableofcontents-2.7.4-py3-none-any.whl Python 3 none any Details for tableofcontents-2.7.4-py3-none-any.whl

Total release size: 53.7 kB

Release files / tableofcontents-2.7.4.tar.gz

Download URL tableofcontents-2.7.4.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8f41c6f116a6119123d201be83162db5f06b1b66a258a2d106fc1c292035fec7
BLAKE2b-256 checksum
How to use checksums
34ff30ab0a54e5224261c39eb75434b83a106faf5dfa291e36436e1d7fccecfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tableofcontents-2.7.4-py3-none-any.whl

Download URL tableofcontents-2.7.4-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9172ab4f7a9df2b7bd796cb7162fbc8b7aa77f7ae938de1943bada005ca7ff16
BLAKE2b-256 checksum
How to use checksums
959c5e4456aace39d1bce2369c9f57323fa4a19c396142ea19641e25c5ea6a94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for tableofcontents 2.7.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page