Skip to content

kaihendry/toc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Creates a table of contents from h1, h2, h3, h4, h5, and h6 elements

Build Status

Demo

An element with data-fill-with="table-of-contents" is filled with an ordered list of the headers.

This allows users to hyperlink directly to answers.

Install

To install:

go install github.com/kaihendry/toc/cmd/toc

To keep upto date:

go get -u github.com/kaihendry/toc/cmd/toc

Example

foo.html contains:

<h1>FAQ</h1>
<nav data-fill-with="table-of-contents" id="toc"></nav>
<h3 id="how-do-i-create-a-faq">How do I create a FAQ?</h3><p>Like this!</p>

Run the tool over the HTML

$ toc foo.html

And something like the following should print to /dev/stdout

<h1>FAQ</h1>
<nav data-fill-with=table-of-contents id=toc>
<ol>
<li><a href=#how-do-i-create-a-faq>How do I create a FAQ?</a>
</ol>
</nav>
<h3 id=how-do-i-create-a-faq>How do I create a FAQ?</h3>
<p>Like this!</p>

As used on:

Acknowledgements

Many thanks to tabatkins's bikeshed for the inspiration & the most helpful Golang programmer I know, Zoltan.