#!/usr/bin/perl -w -I ./
#####!/usr/bin/perl -T -w -I ./
use IO::File;
# stdin: html
# stdout: html with toc
# replace a line with "<TOC>" with table of contents
# generated from header elements: <h1> <h2> etc.
# surrounds each head element with <a name=> element
##open (TOC, "+>DOC");
##open (DOC, "+>TOC");
$toc = IO::File->new_tmpfile();
$doc = IO::File->new_tmpfile();
print ($toc "<center><b><font size=+2>Table of Contents</font></b></center>\n");
$level = 0;
#@paranums;
while ( <STDIN> )
{
###if( /\s*<[hH](\d+)>([^<]*)<\/[hH]\1>/ )
if( /\s*<([hHlL])(\d+)>([^<]*)<\/\1\2>/ )
{
my $hdr = $1;
my $lvl = $2;
my $txt = $3;
if( $lvl < 1 ) { $lvl = 1; }
if( $lvl > $level )
{
$paranums[$lvl-1] = 0;
print ($toc "<dl>\n");
}elsif( $lvl < $level )
{
my $ndx;
for( $ndx=0; $lvl+$ndx < $level; $ndx++ )
{
print ($toc "</dl>\n");
}
}
$level = $lvl;
$paranums[$level-1] += 1;
my $paraname = "";
my $dot = "";
for ( $ndx=0; $ndx<$level; $ndx++ )
{
$paraname = $paraname . $dot . $paranums[$ndx];
$dot = ".";
}
if( "h" eq $hdr || "H" eq $hdr )
{
print ($doc "<a name=\"P$paraname\"><H$lvl>$paraname $txt</H$lvl></a>\n");
print ($toc "<dt><a href=\"#P$paraname\">$paraname $txt</a></dt>\n");
}else{
my @txtprt = split(/;/,$txt,2);
if( @txtprt == 2 )
{
print ($toc "<dt><a href=\"$txtprt[0]\">$paraname $txtprt[1]</a></dt>\n");
}else{
print ($toc "<dt>$paraname $txtprt[0]</H$lvl></dt>\n");
}
}
}else{
s/<header>([^<]*)<\/header>/<table class="header"><tr><td class="header">$1<\/td><\/tr><\/table>/g;
s/<cat>([^<]*)<\/cat>/<span class="cat">$1<\/span>/g;
s/<func>([^<]*)<\/func>/<span class="func">$1<\/span>/g;
s/<map>([^<]*)<\/map>/<span class="map">$1<\/span>/g;
s/<set>([^<]*)<\/set>/<span class="set">$1<\/span>/g;
s/<obj>([^<]*)<\/obj>/<span class="object">$1<\/span>/g;
s/<CAT>([^<]*)<\/CAT>/<span class="category">$1<\/span>/g;
s/<FAM>([^<]*)<\/FAM>/<span class="family">$1<\/span>/g;
s/<FUNC>([^<]*)<\/FUNC>/<span class="functor">$1<\/span>/g;
s/&arrow;/→/g;
s/&rarrow;/←/g; #reverse arrow
s/&monic;/↦/g; #monic arrow
s/&equalize;/↣/g; #equalizer arrow
#s/&eqlz;/∥/g; #equalizer op double bar
s/&eqlz;/≑/g; #equalizer op geometric equality
#s/&cover;/↠/g; #cover arrow
s/&cover;/−⊳/g; #cover arrow
#s/&cover;/⇾/g; #cover arrow
s/&isoarrow;/⥲/g; #isomorphism arrow
s/&darrow;/⇒/g; #double arrow
s/&implies;/⇒/g; #double arrow
s/&rdarrow;/⇐/g; #reverse double arrow
s/&impliedby;/⇐/g; #reverse double arrow
s/⇔/⇔/g; #if and only if
s/&box;/□/g; #source or target operator
s/&opbox;/▣/g; #opposite source or target op
s/&circle;/○/g; #circle
s/&cring;/⊚/g; #circle ring
s/&bullseye;/◎/g; #circle ring
s/&role;/○/g; #role
s/&roleop;/◎/g; #opposite role
s/∀/∀/g;
s/∃/∃/g;
s/¬exist;/∄/g;
s/¬equal;/≠/g;
s/&isomorphic;/≃/g;
s/&mul;/<font face="sans-serif">X<\/font>/g;
s/&add;/+/g;
s/∏/∏/g; # n-ary
s/∐/∐/g; # n-ary
s/∑/∑/g; # n-ary
s/∅/∅/g;
s/&incr;/∆/g;
s/&nable;/∇/g;
s/∈/∈/g;
s/∉/∉/g;
s/&smallisin;/∊/g;
s/&contains;/∋/g;
s/¬contains;/∌/g;
s/&smallcontains;/∍/g;
s/&QED;/∎/g;
s/&slash;/∕/g;
s/∖/∖/g;
s/&asterisk;/∗/g;
s/&compose;/∘/g;
s/&dcomp;/ /g;
s/•/∙/g;
s/&infinity;/∞/g;
s/&logicaland;/∧/g; s/&land;/∧/g;
s/&logicalor;/∨/g; s/&lor;/∨/g;
s/∩/∩/g; s/&intersection;/∩/g;
s/∪/∪/g; s/&union;/∪/g;
s/&bar;/∣/g;
s/⊂/⊂/g;
s/⊃/⊃/g;
s/&direq;/⇉/g; #directed equality, venturi tube
#s/&direq;/≔/g; # :=, directed equality, venturi tube
s/&colonequal;/≕/g; # :=
s/&equalcolon;/≕/g; # =;
s/°ree;/°/g;
s/·/·/g;
s/&inverse;/⁻¹/g;
s/&nland;/⋀/g;
s/&nlor;/⋁/g;
s/&nintersection;/⋂/g;
s/⩃/⋂/g;
s/&nunion;/⋃/g;
s/⩂/⋃/g;
s/⋄/⋄/g;
s/˙/⋅/g;
s/♯/<sup>#<\/sup>/g;
s/&wbullet;/◦/g;
s/&whitebullet;/◦/g;
s/Α/Α/g;
s/Β/Β/g;
s/Γ/Γ/g;
s/Δ/Δ/g;
s/Ε/Ε/g;
s/Ζ/Ζ/g;
s/Η/Η/g;
s/Θ/Θ/g;
s/Ι/Ι/g;
s/Κ/Κ/g;
s/Λ/Λ/g;
s/Μ/Μ/g;
s/Ν/Ν/g;
s/Ξ/Ξ/g;
s/Ο/Ο/g;
s/Π/Π/g;
s/Ρ/Ρ/g;
s/&Stigma;/΢/g;
s/Σ/Σ/g;
s/Τ/Τ/g;
s/Υ/Υ/g;
s/Φ/Φ/g;
s/Χ/Χ/g;
s/Ψ/Ψ/g;
s/Ω/Ω/g;
s/α/α/g;
s/β/β/g;
s/γ/γ/g;
s/δ/δ/g;
s/ε/ε/g;
s/ζ/ζ/g;
s/η/η/g;
s/θ/θ/g;
s/ι/ι/g;
s/κ/κ/g;
s/λ/λ/g;
s/μ/μ/g;
s/ν/ν/g;
s/ξ/ξ/g;
s/ο/ο/g;
s/π/π/g;
s/ρ/ρ/g;
s/&stigma;/ς/g;
s/σ/σ/g;
s/τ/τ/g;
s/υ/υ/g;
s/φ/φ/g;
s/χ/χ/g;
s/ψ/ψ/g;
s/ω/ω/g;
print $doc $_;
}
}
print ($toc "</dl>\n");
seek ($toc,0,0);
seek ($doc,0,0);
while (<$doc>)
{
if( /<[Tt][Oo][Cc]\/?>/ )
{
while ( <$toc> )
{
print;
}
}else{
print;
}
}
close $toc;
close $doc;
#unlink TOC, DOC;
syntax highlighted by Code2HTML, v. 0.9.1