🚩 TOC, zero configuration table of content generator for Markdown files, create table of contents from any Markdown file with ease.

toc

toc TOC, table of content generator for Markdown files

toc gif

Table of Contents


Usage

Usage: toc [options]
Options:
	-p, --path         Path for the markdown file.                               [REQUIRED]
	-a, --append       Append toc after , or write to stdout.          [Default: true]
	-b, --bulleted     Write as bulleted, or write as numbered list.             [Default: true] 
	-s, --skip          Skip the first given number of headers.                   [Default: 0]
	-d, --depth         Set the number of maximum heading level to be included.   [Default: 6]
	-h, --help               Show this message and exit.

Add to your markdown to the place where you want to add Table of Contents. That's it.

Give the markdown file as an input with -p, --path flags.

$ toc -p path/to/markdown.md

Create numbered list instead of bulleted list.

$ toc --bulleted=false

Write result to standard output instead of appending.

$ toc --append=false

Skip the first n number of headers via -s, --skip flags.

$ toc --skip 2

Set the number of maximum heading level to be included with -d, --depth flags.

Set maximum heading level to 3 (h3)

$ toc --depth 3

Installation

Packages

Arch Linux

  • For Arch Linux, install the `` package.

Homebrew

  • For Homebrew on macOS, install the `` formula.

Docker

It is available via two tags.

You can either use latest or $VERSION.

docker run --rm -it yagizcan/toc:latest toc

Downloads

Binary downloads of example are available from the releases section on GitHub for 64-bit Windows, macOS, and Linux targets. They contain the compiled executable.

platform
macOS 64 Bit
Linux 32-Bit
Linux ARM 64 Bit
Linux 64 Bit
Windows 64 Bit
Windows 32 Bit

Installation from source

  1. Verify that you have Go 1.13+ installed

    $ go version
    

    If go is not installed, follow instructions on the Go website.

  2. Clone this repository

    $ git clone https://github.com/ycd/toc 
    $ cd ycd
    
  3. Build and install

    Unix/Linux

    # May require you to use sudo
    $ go build .
    $ cp toc /usr/local/toc
    
  4. Verify installation

    $ toc -h 
    
    Usage: toc [options]
    Options:
       -p, --path         Path for the markdown file.                               [REQUIRED]
       -a, --append       Append toc after , or write to stdout.          [Default: true]
       -b, --bulleted     Write as bulleted, or write as numbered list.             [Default: true] 
       -s, --skip          Skip the first given number of headers.                   [Default: 0]
       -d, --depth         Set the number of maximum heading level to be included.   [Default: 6]
       -h, --help               Show this message and exit.
    

Contributing

All kinds of Pull Requests and Feature Requests are welcomed!

Licence

toc's source code is licenced under the Apache 2.0 License.

Owner
Yagiz Degirmenci
Yagiz Degirmenci
Comments
  • Skipping levels keeps the indentation as they weren't skipped

    Skipping levels keeps the indentation as they weren't skipped

    When you generate a ToC skipping a level the generated ToC keeps the indentation for the bullet as the skipped headers would be there producing a wrong rendering in GH.

    Example

    Original Markdown file (example.md):

    # Header 1
    
    <!-- toc -->
    
    ## Header 2.1
    
    ## Header 2.2
    
    ### Header 2.2.3.1
    
    ### Header 2.2.3.2
    
    

    Result of executing toc -p example.md:

    # Header 1
    
    <!-- toc -->
    - [Header 1](#header-1)
        * [Header 2.1](#header-21)
        * [Header 2.2](#header-22)
            * [Header 2.2.3.1](#header-2231)
            * [Header 2.2.3.2](#header-2232)
    
    <!-- tocstop -->
    
    ## Header 2.1
    
    ## Header 2.2
    
    ### Header 2.2.3.1
    
    ### Header 2.2.3.2
    
    

    It's rendered as image

    Result of executing toc -p example.md -s 1:

    # Header 1
    
    <!-- toc -->
        * [Header 2.1](#header-21)
        * [Header 2.2](#header-22)
            * [Header 2.2.3.1](#header-2231)
            * [Header 2.2.3.2](#header-2232)
    
    <!-- tocstop -->
    
    ## Header 2.1
    
    ## Header 2.2
    
    ### Header 2.2.3.1
    
    ### Header 2.2.3.2
    

    It's rendered as image

  • request: publish docker images

    request: publish docker images

    It would be helpful if toc was available as a docker image. I think a simple scratch container with a static binary in it would be sufficient.

    I'd offer a PR to your goreleaser.yaml but I can't really test it and don't know which docker registry you would prefer.

  • feat: support additional start and end string formats

    feat: support additional start and end string formats

    First, apologies, I don't normally send unsolicited PRs. I was excited when I came across this project because it could improve a common dev and CI workflow we use. Currently we use https://github.com/jonschlinkert/markdown-toc#cli as part of our dev tools to auto-generate README.md TOC's and validate them in CI/CD pipelines. However we had to create a docker container because that tool is written in node.js. Requiring docker in CI pipelines that don't need docker adds a lot of additional time. It would be much more efficient to install a small Go binary to perform our TOC tasks.

    Unfortunately we have hundreds of repos' README.md's that are using the <!-- toc --> / <!-- tocstop --> marker strings so it would be an expensive process to modify all those repos to use your markers and adopt this tool.

    This PR adds compatibility with additional marker string formats and would allow us to easily adopt this tool internally, which I'm very excited about πŸ˜„


    Details:

    Increase compatibility with similar tools.

    • Add support for start string <!-- toc --> (whitespace around 'toc') used by at least these tools:

      1. https://github.com/jonschlinkert/markdown-toc#cli
      2. VSCode Extension 'Markdown All in One': https://github.com/yzhang-gh/vscode-markdown
      3. VSCode Extension 'Markdown TOC': https://github.com/AlanWalk/Markdown-TOC
    • Add support for finish string <!-- tocstop --> used by https://github.com/jonschlinkert/markdown-toc#cli

    • Add support for finish string <!-- /TOC --> used by https://github.com/AlanWalk/Markdown-TOC

    • Marker string matching is now case insensitive as well. This will also increase compatibility with similar tools.

    • The existing start and finish strings will be preserved when generating a new TOC.

  • Fix import pathes

    Fix import pathes

    The fix proposed by #12 was incomplete. The package is still not installable by go install.

    Error message so far:

    Downloading github.com/ycd/toc@main
    go: downloading github.com/ycd/toc v0.3.1-0.20220115220700-b4b973079058
    github.com/ycd/toc imports
            toc/pkg/toc: package toc/pkg/toc is not in GOROOT (/usr/lib/go/src/toc/pkg/toc)
    
  • incorrect go.mod path

    incorrect go.mod path

    Looking over go.mod its currently set to toc. This should be changed to github.com/ycd/toc so this tool can be installed using:

    $ go install github.com/ycd/toc

    It currently fails with this:

    go install: github.com/ycd/toc@latest: github.com/ycd/[email protected]: parsing go.mod:
    	module declares its path as: toc
    	        but was required as: github.com/ycd/toc
    
  • Feature: Add -s --skip flags.

    Feature: Add -s --skip flags.

    This PR adds support for specifying skip option for first n header.

    -s <int> --skip <int>

    Using the --skip 1 flag for the markdown file below should preserve this output:

    Markdown file:

    # Test
    
    # Actual header
    
    # Actual header two
    

    Output

    - [Actual header](#actual-header)
    - [Actual header two](#actual-header-two)
    

    // closes: #4

  • [Feature] Add support for skipping first n headers

    [Feature] Add support for skipping first n headers

    Add support for specifying skip option for first n header.

    -s <int> --skip <int>

    Using the --skip 1 flag for the markdown file below should preserve this output:

    Markdown file:

    # Test
    
    # Actual header
    
    # Actual header two
    

    Expected output

    - [Actual header](#actual-header)
    - [Actual header two](#actual-header-two)
    
    
    
    
  • [Feature] Add flag for for specifying depth.

    [Feature] Add flag for for specifying depth.

    Add support for specifying nested header depth.

    -d <int> --depth <int>

    • For example include only include maximum till h2
    toc -p /path/to/markdown -d 2
    
  • [Fix] Write status messages to stderr instead.

    [Fix] Write status messages to stderr instead.

    Don’t write status messages to stdout.

    • Currently using pipes with --append=false writes
       ~$ toc -p <(curl https://raw.githubusercontent.com/ycd/toc/main/README.md 2>&-) --append=false > toc.md
       ~$ cat toc.md
    
        - [Table of Contents](#table-of-contents)
            * [Usage](#usage)
            * [Installation](#installation)
                * [Packages](#packages)
                * [Downloads](#downloads)
                * [Installation from source](#installation-from-source)
                    * [Unix/Linux](#unixlinux)
            * [Contributing](#contributing)
            * [Licence](#licence)
        βœ” Table of contents generated successfully.
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- This shouldn't be included
    
  • underscore is kept in links

    underscore is kept in links

    Used this and found a small bug only relevant to headings containing _.

    This is the current output:

    - [ISSUE_TEMPLATE.md](#issue-templatemd)
    - [PULL_REQUEST_TEMPLATE.md](#pull-request-templatemd)
    

    These are the ones github uses for its links:

    - [ISSUE_TEMPLATE.md](#issue_templatemd)
    - [PULL_REQUEST_TEMPLATE.md](#pull_request_templatemd)
    

    Or is there another standard which GitHub does not comply to?

Easily to convert JSON data to Markdown Table

Easily to convert JSON data to Markdown Table

Oct 28, 2022
Markdown - Markdown converter for golang

markdown ?? Talks ?? Join ?? Youtube ❀️ Sponsor Install via nami nami install ma

Jun 2, 2022
Mdfmt - A Markdown formatter that follow the CommonMark. Like gofmt, but for Markdown

Introduction A Markdown formatter that follow the CommonMark. Like gofmt, but fo

Dec 18, 2022
tmux-fastcopy aids in copying of text in a tmux pane with ease.
tmux-fastcopy aids in copying of text in a tmux pane with ease.

tmux-fastcopy tmux-fastcopy aids in copying of text in a tmux pane with ease. How? When you invoke tmux-fastcopy, it inspects your tmux pane and overl

Dec 12, 2022
Pryrite, interactively execute shell code blocks in a markdown file
Pryrite, interactively execute shell code blocks in a markdown file

Pryrite Pryrite is a command line tool that interactively runs executable blocks in a markdown file. One can think of pryrite as a console REPL/debugg

Dec 18, 2022
Schedule daily tweets from markdown files in your repo, posted via github actions.

markdown-tweet-scheduler Schedule daily tweets from markdown files in your repo, posted to twitter via github actions. Setup Fork this repo Get your t

Dec 6, 2022
Parse data and test fixtures from markdown files, and patch them programmatically, too.

go-testmark Do you need test fixtures and example data for your project, in a language agnostic way? Do you want it to be easy to combine with documen

Oct 31, 2022
Generate a global index for multiple markdown files recursively
Generate a global index for multiple markdown files recursively

markdown index Markdown-index is a library to help you generate a global index for multiple markdown files recursively in a directory, containing a su

Sep 25, 2022
Convert your markdown files to PDF instantly
Convert your markdown files to PDF instantly

Will take a markdown file as input and then create a PDF file with the markdown formatting.

Nov 7, 2022
Quick and simple parser for PFSense XML configuration files, good for auditing firewall rules

pfcfg-parser version 0.0.1 : 13 January 2022 A quick and simple parser for PFSense XML configuration files to generate a plain text file of the main c

Jan 13, 2022
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS

bluemonday bluemonday is a HTML sanitizer implemented in Go. It is fast and highly configurable. bluemonday takes untrusted user generated content as

Jan 4, 2023
Convert scanned image PDF file to text annotated PDF file
Convert scanned image PDF file to text annotated PDF file

Jisui (θ‡ͺη‚Š) This tool is PoC (Proof of Concept). Jisui is a helper tool to create e-book. Ordinary the scanned book have not text information, so you c

Dec 11, 2022
This command line converts thuderbird's exported RSS .eml file to .html file

thunderbird-rss-html This command line tool converts .html to .epub with images fetching. Install > go get github.com/gonejack/thunderbird-rss-html Us

Dec 15, 2021
Zero-width character detection and removal for Go

go-zero-width Zero-width character detection and removal for Go. Inspired by this Medium article. Installation go get github.com/trubitsyn/go-zero-wid

Jan 8, 2023
Turns any junk text into a usable wordlist for brute-forcing.

haklistgen Turns any junk text into a usable wordlist for brute-forcing. Installation go get -u github.com/hakluke/haklistgen Usage Examples Scrape a

Dec 22, 2022
Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Converts a number to its English counterpart. Uses arbitrary precision; so a number of any size can be converted.

Dec 14, 2021
This service will help you detect any waste of resources in your AWS account

Frugal-Hero This service will help you detect any waste of resources in your AWS account. The policy is: if it is not useful, delete it! Requirements

Jan 31, 2022
Blackfriday: a markdown processor for Go

Blackfriday Blackfriday is a Markdown processor implemented in Go. It is paranoid about its input (so you can safely feed it user-supplied data), it i

Jan 8, 2023
βš™οΈ Convert HTML to Markdown. Even works with entire websites and can be extended through rules.
βš™οΈ Convert HTML to Markdown. Even works with entire websites and can be extended through rules.

html-to-markdown Convert HTML into Markdown with Go. It is using an HTML Parser to avoid the use of regexp as much as possible. That should prevent so

Jan 6, 2023