HXTOC(1)
β¨ HXTOC(1) β¨
okay so bestie, welcome to hxtoc, one of the little legends from the HTML-XML-utils collection π it's the tool that slides a whole table of contents into your HTML like it's decorating your bedroom wall πΈ
π NAME π
hxtoc β insert a table of contents in an HTML file. yes. that's the whole job. and it ate π
π SYNOPSIS π
hxtoc [ -x ] [ -l low ] [ -h high ] [ -t ] [ -d ] [ -c class ] [ -f ] [
file-or-URL ]
π DESCRIPTION π
so here's the vibe, bestie: hxtoc reads an HTML file and goes to work. It inserts the missing ID attributes in all H1 to H6 elements that fall between the levels -l and -h β unless the option -d is in effect, in which case scroll down and read the -d bit, okay? π
Unless the option -t is given, it also inserts A elements with NAME attributes, because old browsers literally do not recognize ID attributes as target anchors. ancestors said no π so we give them the old-school version too.
The output gets written to stdout. classic.
Now β if there's a comment that looks like this:
<!--toc-->
or a pair of comments like this:
<!--begin-toc-->
...
<!--end-toc-->
then that comment, or the pair with everything in between, gets replaced by a table of contents. and what is that TOC made of? a list (UL) of links to all the headers in the document. it's giving navigation, it's giving main character energy π
The text of the headers gets copied into this table of contents, and yes β including any inline markup. The exceptions? ID attributes, DFN tags, and SPAN tags with a CLASS of "index" are omitted. (but the elements' content is still copied, don't worry π«Ά)
The copied text can optionally be "flattened" first β see option -f below.
And one more thing, because it matters: if a header has a CLASS attribute whose value (or one of whose values) is the keyword "no-toc", then that header will not appear in the table of contents. it said "not today" and honestly, respect π
β¨ OPTIONS β¨
The following options are supported:
-xβ Use XML conventions: empty elements are written with a slash at the end, like<IMG />. slay formatting π-l lowβ Sets the lowest numbered header to appear in the table of content. Default is1(i.e.,H1).-h highβ Sets the highest numbered header to appear in the table of content. Default is unlimited. no ceiling, no cap, fr fr π₯-tβ Normally,hxtocadds bothIDattributes and emptyAelements with aNAMEattribute andCLASS="bctarget", so that older browsers that do no understandIDwill still find the target. With this option, theAelements will not be generated.-c classβ The generatedULelements in the table of contents will have aCLASSattribute with the value class. The default is"toc".-dβ Tries to use sectioning elements as targets in the table of contents instead ofH1toH6. A sectioning elements is aDIV,SECTION,ARTICLE,ASIDEorNAVelement that contains at least one heading element (H1toH6) orHGROUP. The sectioning element will be given anIDif it doesn't have one yet. With this option, the level of anyH1toH6that is the first heading of a sectioning element is not determined by its name, but by the nesting depth of the sectioning elements. (AnyH1toH6that are not the first heading of a sectioning element still have their level implied by their name.)-fβ Flatten the text of the table of contents. Without-f, the contents of header elements are copied to the table of contents almost unchanged, i.e., including any child elements and their attributes (except forIDattributes,DFNelements and certainSPANelements, as explained above). With-f, the contents are flattened instead: All child elements are removed and only their contents are copied to the table of contents. Additionally elements with anALTattribute, such asIMG, are replaced by the contents of theALTattribute. Exception:BDOtags are copied unchanged and elements with aDIRattribute are replaced by aSPANwith thatDIRattribute. (BDOandDIRmay occur in languages written right-to-left.) π
π¦ OPERANDS π¦
The following operand is supported:
file-or-URLβ The name or URL of an HTML file. If absent, standard input is read instead. no file? no problem, just pipe it in π«Ά
π DIAGNOSTICS π
The following exit values are returned:
0β Successful completion. we love a clean exit, iconic β> 0β An error occurred in the parsing of the HTML file.hxtocwill try to correct the error and produce output anyway. it's a fixer, it's a healer π§
πΈ SEE ALSO πΈ
asc2xml(1), hxnormalize(1), hxnum(1), xml2asc(1)
go read the whole friend group, they're all so good π
π BUGS π
The error recovery for incorrect HTML is primitive. ngl bestie, it tries its best but it's not a miracle worker π
okay that's the whole page!! version 7.x, dated 10 Jul 2011 β yes she's an elder but she still serves πβ¨ bye bestie, go build that table of contents π
π¦ where this page comes from
- alpine 3.24: html-xml-utils-doc 8.7-r0 Β· W3C
- arch rolling: html-xml-utils 8.8-1 Β· W3C
- fedora 43: html-xml-utils 8.6-2.fc41 Β· W3C AND BSD-3-Clause
- fedora 44: html-xml-utils 8.7-1.fc44 Β· W3C AND BSD-3-Clause
- nixos 26.05: html-xml-utils 8.7
- nixpkgs unstable: html-xml-utils 8.7
- opensuse-leap 16.0: html-xml-utils 8.6-bp160.1.12 Β· W3C
- opensuse-leap 16.0: html-xml-utils 8.6-bp160.1.12 Β· W3C
- opensuse-leap 16.0: html-xml-utils 8.6-bp160.1.12 Β· W3C
- opensuse-leap 16.0: html-xml-utils 8.6-bp160.1.12 Β· W3C
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms