Skip to content

Specification

Thomas Lee edited this page Sep 27, 2018 · 15 revisions

Assume this sample README.md in entire specification pages.

# Sample

## Table of Contents

...

## Installation

### Docker

...

### Build yourself

...

## Usage

### Launch nukes

...

#### Discard nukes

...

Usage

Usage: md-toc FILE [options]

   FILE        The Markdown file to parse for table of contents,
               or "-" to read from stdin

Options:
    -h, --help          print this help message
    -b, --bullet {str}  Custom bullet of the ToC list. (default: "1.")
        --indent {int}  Indentation of the ToC list. (default: 4)
        --max-depth {int}
                        Max depth of headers to include.
        --min-depth {int}
                        Min depth of headers to include. (default: 0)
    -h, --header {str}  Custom header of the ToC. (default: "## Table of
                        Contents")
        --no-link       Exclude links in ToC
        --no-header     Exclude the header of ToC
    -i, --inline        With this flag, the full markdown file will be printed
                        with ToC.
    -r, --replace       Should be used with --inline option and FILE should
                        not be stdin. The original file will be replace
                        instead of printing to standard output.

Generating basic ToC

md-toc README.md

output:

## Table of Contents

1. [Sample](#Sample)
    1. [Table of Contents](#Table-of-Contents)
    1. [Installation](#Installation)
        1. [Docker](#Docker)
        1. [Build yourself](#Build-yourself)
    1. [Usage](#Usage)
        1. [Launch nukes](#Launch-nukes)
            1. [Discard nukes](#Discard-nukes)

Customizing bullets

md-toc README.md --bullet "-" --indent 2

output:

## Table of Contents

- [Sample](#Sample)
  - [Table of Contents](#Table-of-Contents)
  - [Installation](#Installation)
    - [Docker](#Docker)
    - [Build yourself](#Build-yourself)
  - [Usage](#Usage)
    - [Launch nukes](#Launch-nukes)
      - [Discard nukes](#Discard-nukes)
  • default:
    • bullet: "1."
    • indent: 4

Limiting the depth of headers

md-toc README.md --min-depth 1 --max-depth 2

output:

## Table of Contents

1. [Table of Contents](#Table-of-Contents)
1. [Installation](#Installation)
    1. [Docker](#Docker)
    1. [Build yourself](#Build-yourself)
1. [Usage](#Usage)
    1. [Launch nukes](#Launch-nukes)
  • default:
    • min-depth: 0
    • max-depth: None

Extracting links

md-toc README.md --extract-link

output:

## Table of Contents

1. [Sample]
    1. [Table of Contents]
    1. [Installation]
        1. [Docker]
        1. [Build yourself]
    1. [Usage]
        1. [Launch nukes]
            1. [Discard nukes]

[Sample]: #Sample
[Table of Contents]: #Table-of-Contents
[Installation]: #Installation
[Docker]: #Docker
[Build yourself]: #Build-yourself
[Usage]: #Usage
[Launch nukes]: #Launch-nukes
[Discard nukes]: #Discard-nukes

Excluding links

md-toc README.md --no-link

output:

## Table of Contents

1. Sample
    1. Table of Contents
    1. Installation
        1. Docker
        1. Build yourself
    1. Usage
        1. Launch nukes
            1. Discard nukes

Customizing header of ToC

md-toc README.md --header "# ToC"

output:

# ToC

1. [Sample](#Sample)
    1. [Table of Contents](#Table-of-Contents)
    1. [Installation](#Installation)
        1. [Docker](#Docker)
        1. [Build yourself](#Build-yourself)
    1. [Usage](#Usage)
        1. [Launch nukes](#Launch-nukes)
            1. [Discard nukes](#Discard-nukes)
  • default: "## Table of Contents"

Without header

md-toc README.md --no-header

output:

1. [Sample](#Sample)
    1. [Table of Contents](#Table-of-Contents)
    1. [Installation](#Installation)
        1. [Docker](#Docker)
        1. [Build yourself](#Build-yourself)
    1. [Usage](#Usage)
        1. [Launch nukes](#Launch-nukes)
            1. [Discard nukes](#Discard-nukes)
  • default: Unset

Print the full markdown file

md-toc README.md --inline

output:

# Sample

## Table of Contents

1. [Sample](#Sample)
    1. [Table of Contents](#Table-of-Contents)
    1. [Installation](#Installation)
        1. [Docker](#Docker)
        1. [Build yourself](#Build-yourself)
    1. [Usage](#Usage)
        1. [Launch nukes](#Launch-nukes)
            1. [Discard nukes](#Discard-nukes)

## Installation

...

This command will print full markdown file with replaced ToC.

  • ToC's will be placed at:

    • if there is ToC Section (## Table of Contents or desired heading with --header option) already, it will be replaced.
    • else if there is no Level 1 Heading on top of the file, ToC will be placed at the top of the file.
    • else will be placed between the top Level 1 Heading and the following Level 2 Heading
      • if there is other text in this location, ToC will be located at the end of the text
  • default: unset

Replacing the original file

md-toc README.md --inline --replace
  • default: unset