#! D:\perl\bin\perl.exe ############################################################################### ############################################################################### # # To add a table of contents, based on its headings, to an HTML page. # # Version 2 # # by Andrew Hardwick, http://duramecho.com, 2002/3/22 # # Released under GNU Public Licence. # ############################################################################### ############################################################################### # # How To Use # # Run from a command line with the source file name as arguement. # If it finds an existing table of contents from this program then it will # replace it, otherwise it will add a new table at the top of the HTML body # (if you move this, be sure to move the '' # markers as well so that, if you need the table of contents updated, this # program can tell where you want the table of contents to be). # ############################################################################### # # Known Deficiencies # # It ignores commenting out of HTML sections so it may find spurious headings. # It does not check that the anchors it puts in and the HTML the comments it # puts in the HTML to mark the bits it has inserted don't duplicate existing # ones. # ############################################################################### ############################################################################### # Include libraries use Cwd; # To find current directory use strict; # Disenable automatic variables # Global Variables my @HeadingCount; my @HeadingTexts; my @HeadingLevels; my @HeadingLabels; ############################################################################### # Main rountine ############################################################################### { my ($c,$d); # Get data from file my $From=cwd().'/'.$ARGV[0]; open(FILETOPROCESS,'<'.$From)|| die("Cannot open $From to read."); my $Html; read FILETOPROCESS,$Html,-s $From; close FILETOPROCESS; # Remove any old anchors $Html=~s/ .*? //gsx; # Find all headings & mark them with anchors $Html=~s/(.*?)<\/H\1>/ '<\/A>'. $3.'<\/H'.$1.'>'/gise; # Avoid jumping down more than one level at a time by adding null headings for($c=0;$c(.*?)$/$1