toc

command
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Command toc builds a table of contents from a document's headings and inserts it at a marker.

toc -marker '#toc' < page.html > out.html

It reads the document twice, and that is the point rather than an oversight. A table of contents at a marker depends on headings that come after the marker, and one streaming pass cannot insert content it has not seen yet: a StreamFunc is called at the position where its content belongs, not deferred until the end, so a sink registered at the marker runs before the first heading is parsed and would emit an empty list.

So: pass one collects the headings and writes nothing, pass two inserts. The input has to be re-readable, which is why this takes a file rather than a pipe. If it cannot be re-read, the choices are to buffer the whole document, or to put the contents at the end with -at-end, which one pass can do.

Jump to

Keyboard shortcuts

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