Skip to content

lelegard/markdown-toc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Build a Table of Contents in a markdown file

The Python script in this project builds a table of contents in a markdown file.

In the input markdown file, when a line starts with **Contents:**, it marks the start of a table of content. The input file is then modified. A table of content is inserted immediately after this marker line. If a table of content already existed and is different from the new one, it is replaced.

This script is based on the markdown format as used on GitHub.

Usage: markdown-toc [options] md-file ...

Options:

  • -h : print this help text
  • -o : only output table of content, don't update input files
  • -t 'string' : existing ToC header string, default: **Contents:**.

Example: Consider the following markdown file:

# Main title

Introduction....

**Contents:**

## Topic 1
Text...
### Subtopic 1.1
Text...
### Subtopic 1.2
Text...

## Topic 2
Text...
### Subtopic 2.1
Text...

After running the command markdown-toc example.md, the file is updated as follow:

# Main title

Introduction....

**Contents:**

* [Topic 1](#topic-1)
  * [Subtopic 1.1](#subtopic-11)
  * [Subtopic 1.2](#subtopic-12)
* [Topic 2](#topic-2)
  * [Subtopic 2.1](#subtopic-21)

## Topic 1
Text...
### Subtopic 1.1
Text...
### Subtopic 1.2
Text...

## Topic 2
Text...
### Subtopic 2.1
Text...

About

Build table of contents in markdown files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages