Tocer
Tocer (a.k.a. Table of Contenter) is a command line interface for generating table of contents for Markdown files.
Table of Contents
- Features
- Requirements
- Setup
- Usage
- Tests
- Versioning
- Code of Conduct
- Contributions
- License
- History
- Credits
Features
- Supports Markdown ATX-style headers. Example:
# Header.- Does not support header suffixes. Example:
# Header #. - Does not support header prefixes without spaces. Example:
#Header.
- Does not support header suffixes. Example:
- Supports table of contents generation for single or multiple files.
- Supports custom label. Default: "# Table of Contents".
- Supports whitelist filtering. Default: ".md".
- Prepends table of contents to Markdown documents that don't have table of contents.
- Rebuilds Markdown documents that have existing table of contents.
Requirements
- A UNIX-based system.
- Ruby 2.4.x.
Setup
For a secure install, type the following (recommended):
gem cert --add <(curl --location --silent https://www.alchemists.io/gem-public.pem)
gem install tocer --trust-policy MediumSecurity
NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.
For an insecure install, type the following (not recommended):
gem install tocer
Usage
Command Line Interface (CLI)
From the command line, type: tocer --help
tocer -c, [--config] # Manage gem configuration.
tocer -g, [--generate=PATH] # Generate table of contents.
tocer -h, [--help=COMMAND] # Show this message or get help for a command.
tocer -v, [--version] # Show gem version.
For specific --generate options, run tocer --help --generate to see the following:
-l, [--label=LABEL] # Label
# Default: # Table of Contents
-w, [--whitelist=one two three] # File whitelist
# Default: [".md"]
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] -->
Alternatively, you can run tocer -g <directory> on files that do not have Tocer support and it
will prepend the above to your file(s), complete with an auto-generated table of contents.
In the case that Tocer has already 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.
Customization
If desired, this gem supports global customization via the ~/.tocerrc file. Order of precedence is
determined in the following order (with the last one taking top priority):
- Global:
~/.tocerrc. - Local:
<project_root>/.tocerrc. - CLI:
tocer --generate . --label "## Custom Label" --whitelist README.md
Any settings provided to the CLI during runtime will trump the global setting. The global setting is the weakest of all but great for situations where custom settings should be applied to all projects.
The ~/.tocerrc uses the following default settings:
:label: "# Table of Contents"
:whitelist: [".md"]
Each ~/.tocerrc setting can be configured as follows:
label: The header label for the table of contents. Default: "# Table of Contents".whitelist: The list of included files. Default: ".md".
There are multiple ways the whitelist can be defined. Here are some examples:
# Use an empty array to include *all* files.
:whitelist: []
# Use an array of wildcards for groups of files with similar extensions:
:whitelist:
- .md
- .mkd
- .markdown
# Use a mix of wild cards and relative paths to customized as necessary:
:whitelist:
- README.md
- docs/*.md
- .markdown
Tests
To test, run:
bundle exec rake
Versioning
Read Semantic Versioning for details. Briefly, it means:
- Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
Code of Conduct
Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.
Contributions
Read CONTRIBUTING for details.
License
Copyright (c) 2015 Alchemists. Read LICENSE for details.
History
Read CHANGES for details. Built with Gemsmith.
Credits
Developed by Brooke Kuhlmann at Alchemists.