Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bkuhlmann/tocer
A command line interface for generating Markdown table of contents.
https://github.com/bkuhlmann/tocer
markdown table-of-contents toc
Last synced: 2 days ago
JSON representation
A command line interface for generating Markdown table of contents.
- Host: GitHub
- URL: https://github.com/bkuhlmann/tocer
- Owner: bkuhlmann
- License: other
- Created: 2015-11-15T21:53:21.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T01:09:04.000Z (5 days ago)
- Last Synced: 2024-11-05T01:22:20.205Z (5 days ago)
- Topics: markdown, table-of-contents, toc
- Language: Ruby
- Homepage: https://alchemists.io/projects/tocer
- Size: 928 KB
- Stars: 44
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- Funding: .github/FUNDING.yml
- License: LICENSE.adoc
- Citation: CITATION.cff
Awesome Lists containing this project
README
:toc: macro
:toclevels: 5
:figure-caption!:= Tocer
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.toc::[]
== Features
* 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: `"README.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.
. link:https://www.ruby-lang.org[Ruby].== Setup
To install _with_ security, run:
[source,bash]
----
# π‘ Skip this line if you already have the public certificate installed.
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
gem install tocer --trust-policy HighSecurity
----To install _without_ security, run:
[source,bash]
----
gem install tocer
----You can also add the gem directly to your project:
[source,bash]
----
bundle add tocer
----== Usage
=== Command Line Interface (CLI)
From the command line, run: `tocer --help`
image:https://alchemists.io/images/projects/tocer/screenshots/usage.png[Usage,width=581,height=326,role=focal_point]
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:[source,markdown]
--------
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.=== Customization
This gem can be configured via a global configuration: `~/.config/tocer/configuration.yml`.
It can also be configured via link:https://alchemists.io/projects/xdg[XDG] environment
variables.The default configuration is as follows:
[source,yaml]
----
label: "## Table of Contents"
patterns:
- "README.md"
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:
[source,yaml]
----
# Use an empty array to ignore all files:
:patterns: []# Use an array of wildcards for groups of files with similar extensions:
:patterns:
- "*.md"
- "*.mkd"
- "*.markdown"# Use a mix of wild cards and relative names/paths to customized as necessary:
:patterns:
- "README.md"
- "docs/*.md"
- "*.markdown"# Use a recursive glob to traverse and update all sub-directories:
:patterns:
- "**/*.md"
----=== Rake
You can add Rake support by adding the following to your `Rakefile`:
[source,ruby]
----
begin
require "tocer/rake/register"
rescue LoadError => error
puts error.message
endTocer::Rake::Register.call
----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):
[source,bash]
----
rake toc["## Example, *.md"]
----== Development
To contribute, run:
[source,bash]
----
git clone https://github.com/bkuhlmann/tocer
cd tocer
bin/setup
----You can also use the IRB console for direct access to all objects:
[source,bash]
----
bin/console
----== Tests
To test, run:
[source,bash]
----
bin/rake
----== link:https://alchemists.io/policies/license[License]
== link:https://alchemists.io/policies/security[Security]
== link:https://alchemists.io/policies/code_of_conduct[Code of Conduct]
== link:https://alchemists.io/policies/contributions[Contributions]
== link:https://alchemists.io/policies/developer_certificate_of_origin[Developer Certificate of Origin]
== link:https://alchemists.io/projects/tocer/versions[Versions]
== link:https://alchemists.io/community[Community]
== Credits
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
* Engineered by link:https://alchemists.io/team/brooke_kuhlmann[Brooke Kuhlmann].