HYPERTOC(1)
π HYPERTOC(1) π
User Contributed Perl Documentation β hypertoc(1), bestie. Yes, the whole manual name is right there in the header, we're not doing the boring line, we're doing the vibe. π¦
β¨ NAME β¨
hypertoc β generate a table of contents for HTML documents π
πΈ VERSION πΈ
version 3.20 β she's grown, she's evolved, she's iconic β¨
π SYNOPSIS π
okay so first thing, the quick-hit invocations:
hypertoc --help | --manpage | --man_help | --man
and then the full main-character form, literally all the flags at once, look at her go:
hypertoc [--bak string ] [ --debug ] [ --entrysep string ] [ --footer
file ] [ --header file ] [ --ignore_only_one ] [ --ignore_sole_first ] [
--inline ] [ --make_anchors ] [ --make_toc ] [ --notoc_match string ] [
--ol | --nool ] [ --ol_num_levels ] [ --outfile file ] [ --overwrite ] [
--quiet ] [ --textonly ] [ --title string ] { --toc_after tag=suffix } {
--toc_before tag=prefix } { --toc_end tag=endtag } { --toc_entry
tag=level } [ --toc_label string ] [ --toc_only | --notoc_only ] [
--toc_tag string ] [ --toc_tag_replace ] [ --use_id ] [ --useorg ] file
...
note the file ... at the end, you gotta give her files, she's not psychic π
π DESCRIPTION π
so here's the whole deal, bestie. hypertoc lets you name "significant elements" β the divas of your HTML β and then she hyperlinks to them in a "Table of Contents" (ToC) for a given set of HTML documents. periodt.
Basically, the ToC generated is a multi-level level list containing links to the significant elements. hypertoc inserts the links into the ToC to significant elements at a level specified by the user. π«Ά
Example, because examples >>> everything:
If H1s are specified as level 1, than they appear in the first level list of the ToC. If H2s are specified as a level 2, than they appear in a second level list in the ToC. π
There are two aspects to the ToC generation: (1) putting suitable anchors into the HTML documents (--make_anchors), and (2) generating the ToC from HTML documents which have anchors in them for the ToC to link to (--make_toc). One can choose to do one or both of these. β¨
hypertoc also supports the ability to incorporate the ToC into the HTML document itself via the --inline option. lowkey the best feature, ngl.
In order for hypertoc to support linking to significant elements, hypertoc inserts anchors into the significant elements. One can use hypertoc as a filter, outputing the result to another file, or one can overwrite the original file, with the original backed up with a suffix (default: "org") appended to the filename. π
One can also define options in a config file as well as on the command-line. yes queen, options everywhere π
π₯ OPTIONS π₯
housekeeping first: Options can start with"--"or"-"; boolean options can be negated by preceding them with"no"; options with hash or array values can be added to by giving the option again for each value.
See Getopt::Long for more information. iykyk π
--argfilefilename β The name of a file to read more options from. This can be used more than once. For example:
--argfile your.args --argfile my.args
See "Options Files" for more information. (that's down below, keep scrolling bestie π¦)
--bak/--bakstring β If the input file/files is/are being overwritten (--overwriteis on), copy the original file to"filename.string". If the value is empty, there is no backup file written. (default:org) π--debugβ Enable verbose debugging output. Used for debugging this module; in other words, don't bother. π (default:off)--entrysep/--entrysepstring β Separator string for non-<li>item entries (default:", ") β¨--footer/--footerfile β File containing footer text for table of contents. πΈ--header/--headerfile β File containing header text for table of contents. πΈ--helpβ Print a short help message and exit. π«Ά--ignore_only_oneβ If there would be only one item in the ToC, don't make a ToC. (so real, why even bother for one item π )--ignore_sole_firstβ If the first item in the ToC is of the highest level, AND it is the only one of that level, ignore it. This is useful in web-pages where there is only oneH1header but one doesn't know beforehand whether there will be only one. π--inlineβ Put ToC in document at a given point. See "Inlining the ToC" for more information. π--make_anchors|--gen_anchorsβ Create anchors for the table-of-contents to link to. β--make_toc|--gen_tocβ Make a Table-of-Contents which links to anchored significant elements. π--man_help|--manpage|--manβ Print all documentation and exit. (that's the whole thing, all of it, no cap) π--notoc_match/--notoc_matchstring β If there are certain individual tags you don't wish to include in the table of contents, even though they match the "significant elements", then if this pattern matches contents inside the tag (not the body), then that tag will not be included, either in generating anchors nor in generating the ToC. (default:class="notoc") π βοΈ--ol|--noolβ Use an ordered list for Table-of-Contents entries (to a given depth). If--olis false (i.e.--noolis set) then don't use an ordered list for ToC entries.
(default: false)
(See --ol_num_levels to determine how deep the ordered-list listing goes)
--ol_num_levelsβ The number of levels deep the OL listing will go if--olis true. If set to zero, will use an ordered list for all levels. (default:1) π’--outfile/--outfilefile β File to write the output to. This is where the modified HTML output and the Table-of-Contents goes to. If you give'-'as the filename, then output will go toSTDOUT. (default:STDOUT) π¦--overwriteβ Overwrite the input file with the output. If this is in effect,--outfileis ignored. Used ingenerate_anchorsfor creating the anchors "in place" and ingenerate_tocif the--inlineoption is in effect. (default:off) β οΈ careful bestie, she's writing over your stuff--quietβ Suppress informative messages. (default:off) π€«--textonlyβ Use only text content in significant elements. β¨--title/--titlestring β Title for ToC page (if not using--headeror--inlineor--toc_only) (default:"Table of Contents") π--toc_after/--toc_aftertag=suffix β--toc_after "H2=</em>"
For defining layout of significant elements in the ToC. The tag is the HTML tag which marks the start of the element. The suffix is what is required to be appended to the Table of Contents entry generated for that tag. This is a cumulative hash argument. (default: undefined) π
--toc_before/--toc_beforetag=prefix β--toc_before "H2=<em>"
For defining the layout of significant elements in the ToC. The tag is the HTML tag which marks the start of the element. The prefix is what is required to be prepended to the Table of Contents entry generated for that tag. This is a cumulative hash argument. (default: undefined) πΈ
--toc_end/--toc_endtag=endtag β--toc_end "H1=/H1"
For defining significant elements. The tag is the HTML tag which marks the start of the element. The endtag the HTML tag which marks the end of the element. When matching in the input file, case is ignored (but make sure that all your tag options referring to the same tag are exactly the same!). This is a cumulative hash argument. (default: H1=/H1 H2=/H2) π―
--toc_entry/--toc_entrytag=level β--toc_entry "TITLE=1" --toc_entry "H1=2"
For defining significant elements. The tag is the HTML tag which marks the start of the element. The level is what level the tag is considered to be. The value of level must be numeric, and non-zero. If the value is negative, consective entries represented by the significant_element will be separated by the value set by --entrysep option. This is a cumulative hash argument. (default: H1=1 H2=2) π
--toc_label|--toclabel/--toc_labelstring β HTML text that labels the ToC. Always used. (default:"<h1>Table of Contents</h1>") π--toc_only|--notoc_onlyβ Output only the Table of Contents, that is, the Table of Contents plus thetoc_label. If there is a--headeror a--footer, these will also be output.
If --toc_only is false (i.e. --notoc_only is set) then if there is no --header, and --inline is not true, then a suitable HTML page header will be output, and if there is no --footer and --inline is not true, then a HTML page footer will be output.
(default: --notoc_only) π
--toc_tag/--toc_tagstring β If a ToC is to be included inline, this is the pattern which is used to match the tag where the ToC should be put. This can be a start-tag, an end-tag or a comment, but the<should be left out; that is, if you want the ToC to be placed after theBODYtag, then give"BODY". If you want a special comment tag to make where the ToC should go, then include the comment marks, for example:"!--toc--"(default:BODY) π--toc_tag_replaceβ In conjunction with--toc_tag, this is a flag to say whether the given tag should be replaced, or if the ToC should be put after the tag. This can be useful if yourtoc_tagis a comment and you don't need it after you have the ToC in place. (default:false) β¨--use_idβ Useid="name"for anchors rather than<a name="name">anchors. However if an anchor already exists for a Significant Element, this won't make an ID for that particular element. π--useorgβ Use pre-existing backup files as the input source; that is, files of the formfilename.bak(see--bak). π
π FILE FORMATS π
π Options Files π
Options can be given in files as well as on the command-line by using the --argfile filename option in the command-line. Also, the files ~/.hypertocrc and ./.hypertocrc are checked for options. π
The format is as follows: Lines starting with # are comments. Lines enclosed in PoD markers are also comments. Blank lines are ignored. The options themselves should be given the way they would be on the command line, that is, the option name (including the --) followed by its value (if any). π
For example:
# set the ToC to be three-level
--toc_entry H1=1
--toc_entry H2=2
--toc_entry H3=3
--toc_end H1=/H1
--toc_end H2=/H2
--toc_end H3=/H3
Option files can be nested, by giving an --argfile filename argument inside the option file, it will go and get that referred file as well. πͺ nesting dolls energy
See Getopt::ArgvFile for more information. πΈ
β¨ DETAILS β¨
πΈ Significant Elements πΈ
Okay bestie, here's how you actually define the significant elements for your Table of Contents. Let's look at some examples, because examples ate and left no crumbs. π
π Example of Default π
If you don't specify anything at all, this is what you're lowkey getting by default:
--toc_entry "H1=1" --toc_end "H1=/H1" --toc_entry "H2=2" --toc_end "H2=/H2"
Or, if you wrote it out in one of the possible "Options Files":
# default settings
--toc_entry H1=1
--toc_end H1=/H1
--toc_entry H2=2
--toc_end H2=/H2
π Example of before/after π
These ones are serving before/after realness:
# An options file that adds some formatting
# make level 1 ToC entries <strong>
--toc_entry H1=1
--toc_end H1=/H1
--toc_before H1=<strong>
--toc_after H1=</strong>
# make level 2 ToC entries <em>
--toc_entry H2=2
--toc_end H2=/H2
--toc_before H2=<em>
--toc_after H2=</em>
# Make level 3 entries as is
--toc_entry H3=3
--toc_end H3=/H3
π¦ Example of custom end π¦
And these ones are trying to index definition terms, periodt:
# An options file that can work for Glossary type documents
--toc_entry H1=1
--toc_end H1=/H1
--toc_entry H2=2
--toc_end H2=/H2
# Assumes document has a DD for each DT, otherwise ToC
# will get entries with alot of text.
--toc_entry DT=3
--toc_end DT=DD
--toc_before DT=<em>
--toc_after DT=</em>
π Formatting the ToC π
So the --toc_entry and friends let you control how the ToC entries look, but there's a whole other squad of options that change how the final ToC file itself turns out. It's giving glow-up. β¨
With the --header option, whatever's inside the file you name gets prepended before the generated ToC. So you can have intro text, or literally any text, chilling before the ToC.
Note: If you use the--headeroption, make sure the file specified contains the opening HTML tag, the HEAD element (containing the TITLE element), and the opening BODY tag. However, these tags/elements should not be in the header file if the--inlineoptions is used. See "Inlining the ToC" for information on what the header file should contain for inlining the ToC.
With the --toc_label option, the contents of the given string get prepended before the generated ToC (but after any text taken from a --header file). Order matters, bestie. π
With the --footer option, the contents of the file get appended after the generated ToC.
Note: If you use the-footer, make sure it includes the closing BODY and HTML tags (unless, of course, you are using the--inlineoption).
If the --header option is not specified, the appropriate starting HTML markup will be added, unless the --toc_only option is specified. If the --footer option is not specified, the appropriate closing HTML markup will be added, unless the --toc_only option is specified.
If you do not want/need to deal with header, and footer, files, then you are alloed to specify the title, --title option, of the ToC file; and it allows you to specify a heading, or label, to put before ToC entries' list, the --toc_label option. Both options have default values, see "OPTIONS" for more information on each option.
If you do not want HTML page tags to be supplied, and just want the ToC itself, then specify the --toc_only option. If there are no --header or --footer files, then this will simply output the contents of --toc_label and the ToC itself. Simple as. π
π§ Inlining the ToC π§
The ability to incorporate the ToC directly into an HTML document is supported via the --inline option. Main character energy, honestly.
Inlining will be done on the first file in the list of files processed, and will only be done if that file contains an opening tag matching the --toc_tag value.
If --overwrite is true, then the first file in the list will be overwritten, with the generated ToC inserted at the appropriate spot. Otherwise a modified version of the first file is output to either STDOUT or to the output file defined by the --outfile option.
The options --toc_tag and --toc_tag_replace are used to determine where and how the ToC is inserted into the output.
β Example 1 β
# this is the default
--toc_tag BODY --notoc_tag_replace
This will put the generated ToC after the BODY tag of the first file. If the --header option is specified, then the contents of the specified file are inserted after the BODY tag. If the --toc_label option is not empty, then the text specified by the --toc_label option is inserted. Then the ToC is inserted, and finally, if the --footer option is specified, it inserts the footer. Then the rest of the input file follows as it was before. Chef's kiss ordering. π
π Example 2 π
--toc_tag '!--toc--' --toc_tag_replace
This will put the generated ToC after the first comment of the form <!--toc-->, and that comment will be replaced by the ToC (in the order
--header
--toc_label
ToC
--footer
) followed by the rest of the input file.
Note: The header file should not contain the beginning HTML tag and HEAD element since the HTML file being processed should already contain these tags/elements.
π₯ EXAMPLES π₯
π«Ά Create an inline ToC for one file π«Ά
hypertoc --inline --make_anchors --overwrite --make_toc index.html
This will create anchors in "index.html", create a ToC with a heading of "Table of Contents" and place it after the BODY tag of "index.html". The file index.html.org will contain the original index.html file, without ToC or anchors. Backup queen. π
πΈ Create a ToC file from multiple files πΈ
First, create the anchors.
hypertoc --make_anchors --overwrite index.html fred.html george.html
Then create the ToC
hypertoc --make_toc --outfile table.html index.html fred.html george.html
β¨ Create an inline ToC after the first heading of the first file β¨
hypertoc --make_anchors --inline --overwrite --make_toc --toc_tag /H1 \
--notoc_tag_replace --toc_label "" index.html fred.html george.html
This will create anchors in the "index.html", "fred.html" and "george.html" files, create a ToC with no header and place it after the first H1 header in "index.html" and back up the original files to "index.html.org", "fred.html.org" and "george.html.org"
π Create an inline ToC with custom elements π
hypertoc --quiet --make_anchors --bak "" --overwrite \
--make_toc --inline --toc_label "" --toc_tag '!--toc--' \
--toc_tag_replace \
--toc_entry H2=1 --toc_entry H3=2 \
--toc_end H2=/H2 --toc_end H3=/H3 myfile.html
This will create an inline ToC overwriting the original file, and replacing a <!--toc--> comment, and which takes H2 headers as level 1 and H3 headers as level 2. This can be useful where the .html file is generated by some other process, and you can then create the ToC as the last step. So convenient, no cap. π
π¦ Create a ToC with custom elements π¦
hypertoc --quiet --make_anchors --bak "" --overwrite \
--toc_entry TITLE=1 --toc_end TITLE=/TITLE
--toc_entry H2=2 --toc_entry H3=3 \
--toc_end H2=/H2 --toc_end H3=/H3 \
--make_toc --outfile index.html \
mary.html fred.html george.html
This creates anchors at the H2 and H3 elements, and creates a ToC file called index.html, indexing on the TITLE, and the H2 and H3 elements.
π Create a ToC with custom elements and options file π
Given an options file called 'custom.opt' as follows:
# Title, H2 and H3
--toc_entry TITLE=1
--toc_end TITLE=/TITLE
--toc_entry H2=2
--toc_end H2=/H2
--toc_entry H3=3
--toc_end H3=/H3
then the previous example can have shorter command lines as follows:
hypertoc --quiet --make_anchors --bak "" --overwrite \
--argfile custom.opt --make_toc --outfile index.html mary.html fred.html george.html
π NOTES π
hypertocis smart enough to detect anchors inside significant elements. If the anchor defines the NAME attribute,hypertocuses the value. Else, it adds its own NAME attribute to the anchor. If--use_idis true, then it likewise checks for and uses IDs. Detective behavior fr fr. π- The TITLE element is treated specially if specified as a significant element. It is illegal to insert anchors (A) into TITLE elements. Therefore,
hypertocwill actually link to the filename itself instead of the TITLE element of the document. hypertocwill ignore a significant element if it does not contain any non-whitespace characters. A warning message is generated if such a condition exists.- If you have a sequence of significant elements that change in a slightly disordered fashion, such as H1 -> H3 -> H2 or even H2 -> H1, though
hypertocdeals with this to create a list which is still good HTML, if you are using an ordered list to that depth, then you will get strange numbering, as an extra list element will have been inserted to nest the elements at the correct level.
For example (H2 -> H1 with --ol_num_levels=1):
1.
* My H2 Header
2. My H1 Header
For example (H1 -> H3 -> H2 with --ol_num_levels=0 and H3 also being significant):
1. My H1 Header
1.
1. My H3 Header
2. My H2 Header
2. My Second H1 Header
In cases such as this it may be better not to use the --ol option.
- If one is not using
--overwritewhen generating anchors, then the command needs to be done in two passes, in order to give the correct filenames (the ones with the actual anchors in them) to the ToC generation part. Otherwise the ToC will have anchors pointing to files that don't have them. π - When using
--inline, care needs to be taken if overwriting -- if one sets the ToC to be included after a given tag (such as the default BODY) then if one runs the command repeatedly one could get multiple ToCs in the same file, one after the other. Not the vibe check you want. π
π CAVEATS π
okay bestie, listen up, because this is the part where we keep it real. no cap, there are some things you just gotta know.
- Version 3.10 (and above) generates more verbose (SEO-friendly) anchors than prior versions. so like... anchors you made with earlier versions will not match version 3.10 anchors. they just won't. different vibe, different anchor. π
- Version 3.00 (and above) of
hypertocbehaves somewhat differently than Version 2.x ofhypertoc. it's now designed to do everything in one pass, and it has dropped certain options, so let's do a little roll call of the fallen π«‘:- the
--infileoption is no longer used (all filenames are put at the end of the command, periodt); - the
--toc_fileoption no longer exists β use the--outfileoption instead, she's the replacement; - the
--tocmapoption is no longer supported. gone. bye. π
- the
It also now generates lower-case tags rather than upper-case ones. lowercase era, we love to see it.
- lowkey sad but true:
hypertocis not very efficient (memory and speed), and can be slow for large documents. she's doing her best but she's not fast, okay?? π - now that generation of anchors and of the ToC are done in one pass, even more memory is used than was the case before. this is more notable when processing multiple files, since all files are read into memory before processing them. so like... all of them. at once. in the brain. π§ β¨
- Invalid markup will be generated if a significant element is contained inside of an anchor. for example:
<a name="foo"><h1>The FOO command</h1></a>
will be converted to (if h1 is a significant element),
<a name="foo"><h1><a name="The">The</a> FOO command</h1></a>
which is illegal since anchors cannot be nested. illegal!! π¨ the markup police are outside, bestie.
It is better style to put anchor statements within the element to be anchored. For example, the following is preferred:
<h1><a name="foo">The FOO command</a></h1>
hypertoc will detect the "foo" NAME and use it. she's smart like that. π
Even better is to use IDs:
<h1 id="foo">The FOO command</h1>
- NAME attributes without quotes are not recognized. nope. not happening. put the quotes on, it's giving β¨quotationβ¨.
π BUGS π
Tell me about them.
that's it. that's the whole section. she's literally just asking you to snitch on the bugs. do it. π
π§ REQUIRES π§
Getopt::LongGetopt::ArgvFileFile::BasenamePod::UsageHTML::LinkListHTML::EntitiesHTML::GenToc
π SCRIPT CATEGORIES π
- Web
πΈ ENVIRONMENT πΈ
HOMEβhypertoclooks in theHOMEdirectory for config files. she's checking your house. π
π FILES π
"~/.hypertocrc"β User configuration file.".hypertocrc"β Configuration file in the current working directory; overrides options in"~/.hypertocrc"and is overridden by command-line options.
so the hierarchy goes: command-line options π >".hypertocrc">"~/.hypertocrc". command line is the main character, always.
π SEE ALSO π
perl(1) htmltoc(1) HTML::GenToc Getopt::ArgvFile Getopt::Long
π AUTHOR π
Kathryn Andersen β http://www.katspace.org/tools/hypertoc/
Based on htmltoc by Earl Hood β ehood AT medusa.acs.uci.edu
Contributions from Dan Dascalescu, <http://dandascalescu.com>
β COPYRIGHT β
Copyright (C) 1994-1997 Earl Hood, ehood AT medusa.acs.uci.edu Copyright (C) 2002-2008 Kathryn Andersen
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
and that's a wrap on HYPERTOC(1) bestie!! πβ¨ this lil beauty shipped as perl v5.42.0 on 2025-07-25, and honestly? iconic. go make some tables of contents, you absolute legend. mwah π
π«Ά
π¦ where this page comes from
- fedora 43: perl-HTML-GenToc 3.20-41.fc43 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms