+
Skip to content

jar-b/mdtoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mdtoc

Go Reference

Generate a table of contents for an existing markdown document. The table of contents will link to anchor tags, and preserve the level of nesting.

CLI

Installation

Via go get:

go get github.com/jar-b/mdtoc/cmd/mdtoc

Usage

$ mdtoc -h
Usage: mdtoc [flags] [filename]

Flags:
  -dry-run
    	print generated contents, but do not write to file (optional)
  -force
    	force overwrite of existing contents (optional)
  -out string
        output file (optional, defaults to adding to source file)

Examples:

# add new
mdtoc mydoc.md

# dry run
mdtoc -dry-run mydoc.md

# force overwrite of existing
mdtoc -force mydoc.md

Library

import github.com/jar-b/mdtoc

Usage

package main

import (
	"fmt"
	"log"

	"github.com/jar-b/mdtoc"
)

func main() {
	b := []byte("# Title\ndescription text\n\n## Heading 1\ntext\n## Heading 2\nmore text")

	toc, err := mdtoc.Parse(b)
	if err != nil {
		log.Fatal(err)
	}

	new, err := mdtoc.Add(b, toc, false)
	if err != nil {
		log.Fatal(err)
	}

	// do something with `new`
	fmt.Println(string(new))
}

About

Generate a table of contents for an existing markdown document.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载