The letter A styled as Alchemists logo. lchemists
Published November 15, 2015 Updated January 28, 2024
Tocer Icon



Tocer (a.k.a. Table of Contenter) is a command line interface for generating table of contents for Markdown files. Use this tool to automatically manage and update your documentation with minimal effort. Works on single files or multiple files within nested directory structures.


  • Supports Markdown ATX-style headers. Example: # Header.

    • Does not support header suffixes. Example: # Header #.

    • Does not support header prefixes without spaces. Example: #Header.

  • Supports table of contents generation for single or multiple files.

  • Supports custom label. Default: ## Table of Contents.

  • Supports file list filtering. Default: "".

  • Prepends table of contents to Markdown documents that don’t have table of contents.

  • Rebuilds Markdown documents that have existing table of contents.


  1. A UNIX-based system.

  2. Ruby.


To install with security, run:

# 💡 Skip this line if you already have the public certificate installed.
gem cert --add <(curl --compressed --location
gem install tocer --trust-policy HighSecurity

To install without security, run:

gem install tocer

You can also add the gem directly to your project:

bundle add tocer


Command Line Interface (CLI)

From the command line, run: tocer --help


To generate the table of contents at a specific position within your Markdown files, add the following lines to your file(s) prior to generation:

<!-- Tocer[start] -->
<!-- Tocer[finish] -->

In the case that Tocer has auto-generated a table of contents for a Markdown file; the existing table of contents has become stale; or placement of the table of contents has changed, you can re-run Tocer on that file to auto-update it with new table of contents.


This gem can be configured via a global configuration: ~/.config/tocer/configuration.yml.

It can also be configured via XDG environment variables.

The default configuration is as follows:

label: "## Table of Contents"
  - ""
root_dir: "."

Feel free to take this default configuration, modify, and save as your own custom configuration.yml.

The configuration.yml file can be configured as follows:

  • label: The header label for the table of contents.

  • patterns: The list of included files.

  • root_dir: The root path to use for processing files.

There are multiple ways the include list can be defined. Here are some examples:

# Use an empty array to ignore all files:
:patterns: []

# Use an array of wildcards for groups of files with similar extensions:
  - "*.md"
  - "*.mkd"
  - "*.markdown"

# Use a mix of wild cards and relative names/paths to customized as necessary:
  - ""
  - "docs/*.md"
  - "*.markdown"

# Use a recursive glob to traverse and update all sub-directories:
  - "**/*.md"


You can add Rake support by adding the following to your Rakefile:

  require "tocer/rake/register"
rescue LoadError => error
  puts error.message

Once required and registered, the following tasks will be available (i.e. bundle exec rake -T):

rake toc[label,includes]   # Insert/Update Table of Contents

You can invoke the task as follows (quotes are only necessary if spaces are used):

rake toc["## Example, *.md"]


To contribute, run:

git clone
cd tocer

You can also use the IRB console for direct access to all objects:



To test, run: