Generate Table of Contents for an HTML Page

(Version 1)

What is It?

It is a program which will add a table of contents into an HTML page.

It will use the headings ('<H1>...</H1>', '<H2>...</H2>' for heading levels 1 & 2 etc.) in the HTML page as contents markers. The resulting table of contents will have entries indented according to the level of the heading and the entries will be linked to relevant sections so readers can jump to them by clicking in the table of contents.

If it finds a previous table of contents generated by this program then it will be replaced, otherwise a new table of contents will be put at the beginning of the page (from where you can move it to where you prefer and subsequent updates will maintain that position).

You can see the type of table of contents it generates in the following to pages which are trivial page before & after running the program on it.

System Requirements

A Perl interpreter.

How to Use It

To create a table of contents, just run it from a command line with the name (or path relative to the current working directory) of the HTML file to process as its sole parameter.

If the table of contents is not in the place in the HTML document you want it to be, just open the document in a plain text editor and move whole table of contents (everything from '<!--TableOfContents:Begin-->' to '<!--TableOfContents:End-->' inclusive) to where you want it. Remember to move those two '<!--TableOfContents:...-->' hidden comments with the table of contents because that will tell the program where to put the table of contents when updating it so you won't have to move it again.

To update a table of contents, just run the program as when creating it initially. The program will automatically detect the old table of contents & replace it. Note that HTML is not a page numbered format so there is no need to update the table of contents after editing the HTML unless the headings change.

Known Deficiencies


Download (6 Kb).

Other Perl Scripts, Disclaimers Etc.

See my computer programs index page for more simple useful computer programs.