/markdown_toc

A Ruby script for generating a Markdown Table of Contents

Primary LanguageRubyMIT LicenseMIT

mdtoc.rb

Release 1.0.2.

Build Status

Overview

This script can be used to generate a Markdown Table of Contents from a Markdown source document. For more information, see my related blog post.

Dependencies

You only require a system Ruby. Tested on Ruby versions 1.9 through to 2.7.

Installation

Install by copying the script from the master branch:

▶ curl \
  https://raw.githubusercontent.com/alexharv074/markdown_toc/master/mdtoc.rb -o \
  /usr/local/bin/mdtoc.rb

Usage

Help message:

▶ mdtoc.rb -h
Usage: mdtoc.rb FILE.md [TOP [MAX]] [-h]
     FILE.md          Markdown source document
     TOP              top-level Markdown heading level (default 2)
     MAX              maximum heading level (default 4)

On Mac OS X, the pbcopy command is useful, for example:

▶ mdtoc.rb README.md | pbcopy
▶ vim README.md # then paste in the ToC!

More examples

Look in the tests.

License

MIT.