Creates a table of contents from h1, h2, h3, h4, h5, and h6 elements
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.
To install:
go install github.com/kaihendry/toc/cmd/toc To keep upto date:
go get -u github.com/kaihendry/toc/cmd/toc 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:
Many thanks to tabatkins's bikeshed for the inspiration & the most helpful Golang programmer I know, Zoltan.
