Giter Site home page Giter Site logo

tocer's Introduction

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.

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

  1. A UNIX-based system.

  2. Ruby.

Setup

To install with security, run:

# πŸ’‘ 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:

gem install tocer

You can also add the gem directly to your project:

bundle add tocer

Usage

Command Line Interface (CLI)

From the command line, run: tocer --help

Usage

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.

Customization

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"
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:

# 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:

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

Tocer::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):

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

Development

To contribute, run:

git clone https://github.com/bkuhlmann/tocer
cd tocer
bin/setup

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

bin/console

Tests

To test, run:

bin/rake

Credits

tocer's People

Contributors

bkuhlmann avatar olleolleolle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

olleolleolle

tocer's Issues

[Documentation] Would it be possible to add an example how to use tocer from within a simple .md file (in the main README)?

Hello Brooke,

I just noticed your tocer-gem on rubygems.org.

I use markdown for my gems and admittedly, I use a very simple markdown.

Other than headers and bold text, and an image here or there, I think that sums up
most of my markdown-use so far in the last ... two years or so. :-)

Anyway, to my suggestion:

But I am not entirely sure how to use tocer from an existing .md file.

If you could add a minimum example for the next tocer release, that would be
great! Feel free to close this issue at any moment in time.

Thanks!

Ruby comments in code blocks are included as ToC entries

Expected Behavior

When a document has ruby code blocks that contain comments, the comments should not be included in the table of contents.

The following document is an example of what should happen:

<!-- Tocer[start]: Auto-generated, don't remove. -->

# Table of Contents

- [Introduction](#introduction)
  - [Code Blocks](#code-blocks)

<!-- Tocer[finish]: Auto-generated, don't remove. -->


# Introduction

Text here

## Code Blocks

```ruby
# This is a comment describing the code
class MyRubyClass
end
```

Actual Behavior

The actual behavior is to include ruby comments as table of contents entries:

<!-- Tocer[start]: Auto-generated, don't remove. -->

# Table of Contents

- [Introduction](#introduction)
  - [Code Blocks](#code-blocks)
- [This is a comment describing the code](#this-is-a-comment-describing-the-code)

<!-- Tocer[finish]: Auto-generated, don't remove. -->


# Introduction

Text here

## Code Blocks

```ruby
# This is a comment describing the code
class MyRubyClass
end
```

Steps to Recreate

  1. Run tocer -g README.md inside the eebs/tocer_test repo.

Environment

Tocer 3.1.1
Ruby 2.3.1
OSX 10.11.6

Adds blank lines to files with no markdown headers

Overview

We have a markdown file in our wiki with no #header elements:

Design assets like logos and icons can be found on Google Drive.
https://drive.google.com/drive/u/3/folders/xyz

An automated script runs tocer to generate a TOC for all markdown files in the directory. This file currently has 12,150 blank lines preceeding the two lines of content, and 12162 commits in the git log for it.

Screenshots/Screencasts

Steps to Recreate

$ tail Design-Resources.md








Design assets like logos and icons can be found on Google Drive.
https://drive.google.com/drive/u/3/folders/xyz

$ tocer --version
Tocer 12.0.1

$ tocer -b -i Design-Resources.md
  Design-Resources.md

$ git diff | xclip
diff --git a/Design-Resources.md b/Design-Resources.md
index 4491ed77..d8bfcb56 100644
--- a/Design-Resources.md
+++ b/Design-Resources.md
@@ -12148,6 +12148,7 @@
 
 
 
+
 
 
 Design assets like logos and icons can be found on Google Drive.

Desired Behavior

Tocer should not modify files if it did not make any changes.

Environment

$ uname -a
Linux ava.home 5.11.20-200.fc33.x86_64 #1 SMP Wed May 12 12:48:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

$ ruby --version
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

$ gem --version
3.2.15

$ tocer --version
Tocer 12.0.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.