48 |
|
|
49 |
if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) { |
if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) { |
50 |
$new_title = $1; |
$new_title = $1; |
51 |
} elsif ($contents =~ m,<h\d\sclass="docPartTitle"[^>]*>(.+?)</h\d>,is) { |
} elsif ($contents =~ m,<(h\d)\sclass="docPartTitle"[^>]*>(.+?)<\1>,is) { |
52 |
$new_title = $1; |
$new_title = $2; |
53 |
} elsif ($contents =~ m,<h\d\sclass="docChapterTitle"[^>]*>(.+?)</h\d>,is) { |
} elsif ($contents =~ m,<(h\d)\sclass="docChapterTitle"[^>]*>(.+?)<\1>,is) { |
54 |
$new_title = $1; |
$new_title = $2; |
55 |
} elsif ($contents =~ m,<h\d\sclass="docSection1Title"[^>]*>(.+?)</h\d>,is) { |
} elsif ($contents =~ m,<(h\d)\sclass="docSection1Title"[^>]*>(.+?)<\1>,is) { |
56 |
$new_title = $1; |
$new_title = $2; |
57 |
} elsif ($contents =~ m,<h\d\sclass="chapter"[^>]*>(.+?)</h\d>,is) { |
} elsif ($contents =~ m,<(h\d)\sclass="chapter"[^>]*>(.+?)<\1>,is) { |
58 |
$new_title = $1; |
$new_title = $2; |
59 |
} elsif ($contents =~ m,<h\d\sclass="sect1"[^>]*>(.+?)</h\d>,is) { |
} elsif ($contents =~ m,<(h\d)\sclass="sect1"[^>]*>(.+?)<\1>,is) { |
60 |
$new_title = $1; |
$new_title = $2; |
61 |
} else { |
} else { |
62 |
if ($contents =~ m,<title>([^<]+)</title>,is) { |
if ($contents =~ m,<title>([^<]+)</title>,is) { |
63 |
$new_title = $1; |
$new_title = $1; |
89 |
|
|
90 |
if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) { |
if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) { |
91 |
print STDERR "replace title '$1' with '$new_title'\n" if ($verbose); |
print STDERR "replace title '$1' with '$new_title'\n" if ($verbose); |
92 |
} elsif ( |
} elsif ($contents =~ s,(<head>),$1<title>$new_title</title>,is) { |
93 |
# try to insert after <head>, <html> or at top |
print STDERR "adding title '$new_title' after <head>\n" if ($verbose); |
94 |
$contents =~ s,(<head>),$1<title>$new_title</title>,is || |
|
95 |
$contents =~ s,(<html>),$1<title>$new_title</title>,is || |
} elsif ($contents =~ s,(<html>),$1<head><title>$new_title</title></head>,is) { |
96 |
$contents =~ s,^,<title>$new_title</title>, ) { |
print STDERR "adding title '$new_title' after <html>\n" if ($verbose); |
97 |
|
|
98 |
|
} elsif ($contents =~ s,^,<title>$new_title</title>,) { |
99 |
print STDERR "adding new title '$new_title'\n" if ($verbose); |
print STDERR "adding new title '$new_title'\n" if ($verbose); |
100 |
|
} else { |
101 |
|
print STDERR "WARNING: filter couldn't add new title '$new_title' anywhere!"; |
102 |
} |
} |
103 |
|
|
104 |
return $contents; |
return $contents; |