Skip to content

Commit 9bd314a

Browse files
committed
[CSS21] Remove navbar in single-page version.
1 parent 914790f commit 9bd314a

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

css21/bin/htmlcat

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
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

811
if (!$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:
3045
readfile($ARGV[0]);
3146
$_ = $buf;
47+
# Remove navbar
48+
s/<div\b[^>]*\bclass=["']?navbar\b[^>]*>.*?<\/div>//sigo;
49+
s/<hr\b[^>]*\bclass=["']?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
3253
if (/<\/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
4162
foreach $file (@ARGV) {
4263
readfile($file);
43-
# look for the beginning of the body content
4464
$_ = $buf;
65+
# Remove navbar
66+
s/<div\b[^>]*\bclass=["']?navbar\b[^>]*>.*?<\/div>//sigo;
67+
s/<hr\b[^>]*\bclass=["']?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

Comments
 (0)