toc

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 15 Imported by: 0

README

toc - 🚩 Zero configuration table of content generator for Markdown files.

toc is a command-line tool and a Go library for generating table of contents form Markdown files.

Build Status

Quick Start

go install go.mills.io/toc/cmd/toc@latest

Add <!--toc--> to your markdown to the place where you want to add Table of Contents. That's it.

Give the markdown file as an input by providing it as the first argument.

toc path/to/markdown.md

Create numbered list instead of bulleted list.

toc -l

Write result in-place to the file instead of standard output.

toc -w

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

toc -s 2

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

Set maximum heading level to 3 (h3)

toc -d 3

Features

  • Zero configuration
  • Write in-place or to stdout
  • Specify depth level
  • Skip headings
  • Use bulleted or numbered lists

Installation

Download the binaries from go.mills.io/prologic/toc:

go install go.mills.io/toc/cmd/toc@latest

Or build from source manually:

git clone https://git.mills.io/prologic/toc
cd toc
make install

Licence

toc is licensed under the terms of the MIT License and was originally forked from @ycd's ycd/toc also licensed under an MIT License.

Documentation

Overview

Package toc creates table of contents from Markdown files

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is the tagged release version in the form <major>.<minor>.<patch>
	// following semantic versioning and is overwritten by the build system.
	Version = defaultVersion

	// Commit is the commit sha of the build (normally from Git) and is overwritten
	// by the build system.
	Commit = defaultCommit

	// Build is the date and time of the build as an RFC3339 formatted string
	// and is overwritten by the build system.
	Build = defaultBuild
)

Functions

func FullVersion

func FullVersion() string

FullVersion display the full version and build

Types

type Option

type Option func(opts *Options) error

Option is a function for defining new functional options

func WithBulleted

func WithBulleted() Option

WithBulleted users bulleted lists

func WithDepth

func WithDepth(depth int) Option

WithDepth considers only headings n deep

func WithList

func WithList() Option

WithList uses numbered lists

func WithPath

func WithPath(path string) Option

WithPath configures the input path of the Markdown file being read from (and/or written to)

func WithSkip

func WithSkip(skip int) Option

WithSkip skips n number of headings

func WithWrite

func WithWrite() Option

WithWrite enables in-place writing of the table of contents to the Markdown file

type Options

type Options struct {
	Bulleted bool
	Depth    int
	List     bool
	Skip     int
	Path     string
	Write    bool
}

Options holds configuration options for generating a table of contents

type Toc

type Toc struct {
	// contains filtered or unexported fields
}

Toc creates table of contents from Markdown files

func New

func New(options ...Option) (*Toc, error)

New creates a new Toc with options

func (*Toc) Run

func (t *Toc) Run(w io.Writer) error

Run runs the toc processor with the configured options

func (*Toc) String

func (t *Toc) String() (s string)

Directories

Path Synopsis
cmd
toc
Package main is the toc command-line tool
Package main is the toc command-line tool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL