33# Arnaud Le Hors - lehors@w3.org
44# $Id: htmlcat,v 1.4 2006-10-09 18:55:52 ihickson Exp $
55
6+ use lib ' bin' ;
7+ use utils;
8+
69$PROGNAME = substr ($0 , rindex ($0 , " /" ) + 1);
710
811if (!$ARGV [0]) {
@@ -26,9 +29,27 @@ sub readfile {
2629 close (INPUT);
2730}
2831
29- # 1st file: take everything up to the body end tag or the end otherwise
32+ # Convert a file name to the first anchor in that file (#q7.0)
33+ sub guess_anchor {
34+ my ($file , $fragment ) = @_ ;
35+ my $chapno = $lookup {$file };
36+ if (!defined $chapno ) {return $file . $fragment ;} # Not a chapter
37+ elsif (defined $fragment ) {return $fragment ;} # Fragment of a chapter
38+ else {return " #q" . $chapno . " .0" ;} # Guess anchor of first H1 in that file
39+ }
40+
41+ # Read config file
42+ read_config(' Project.cfg' );
43+
44+ # 1st file:
3045readfile($ARGV [0]);
3146$_ = $buf ;
47+ # Remove navbar
48+ s / <div\b [^>]*\b class=["']?navbar\b [^>]*>.*?<\/ div>// sigo ;
49+ s / <hr\b [^>]*\b class=["']?navbar\b [^>]*>// sigo ;
50+ # Fix local links: "foo.html" -> "#q7.0" and "foo.html#bar" -> "#bar"
51+ s / (href=")([a-z0-9]+\. html)(#[a-z0-9.-]+)?"/ $1 .guess_anchor($2 , $3 ).'"'/ gie ;
52+ # take everything up to the body end tag or the end otherwise
3253if (/ <\/ body>/sio ) {
3354 print OUTPUT $` ;
3455} else {
@@ -40,8 +61,15 @@ shift;
4061# then for each other given html file only take the body content
4162foreach $file (@ARGV ) {
4263 readfile($file );
43- # look for the beginning of the body content
4464 $_ = $buf ;
65+ # Remove navbar
66+ s / <div\b [^>]*\b class=["']?navbar\b [^>]*>.*?<\/ div>// sigo ;
67+ s / <hr\b [^>]*\b class=["']?navbar\b [^>]*>// sigo ;
68+ # Fix local links: "foo.html#bar" -> "#bar"
69+ s / (href=")([a-z0-9]+\. html)(#[a-z0-9.-]+)?"/ $1 .guess_anchor($2 , $3 ).'"'/ gie ;
70+ # Remove warning
71+ s / <!-- warning -->.*?<!-- \/ warning -->// gs ;
72+ # look for the beginning of the body content
4573 if (/ <body>(.*)/sio ) {
4674 $buf = $1 ;
4775 } elsif (/ <\/ head>/sio ) {
0 commit comments