-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkhtml.pl
executable file
·98 lines (76 loc) · 1.98 KB
/
mkhtml.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env perl
#
# Simple script for basic HTML formatting of built-in man page.
#
use Getopt::Std; # command line options
getopts('t');
# table of contents
if ( $opt_t ) {
# Make index
$man = 0; # where NAME has beeing found yet
$hasName = 0;
HLINE: while (<>) {
$line = $_;
chomp $line;
@tokens = split " ", "$line";
if ( "$tokens[0]" eq "NAME" ) {
$man = 1;
next HLINE;
}
$man = 0 if ( "$tokens[0]" eq "<RC>" );
next HLINE unless($man);
print <<'EOF';
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/\
xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="/pod.css" type="text/css" />
</head>
EOF
if ( length($line) ) {
unless ( $hasName ) {
print "<h1> $line </h1>\n";
print "<ul>\n";
print "<li> <a href=\#NAME > NAME </a></li>\n";
$hasName=1;
next HLINE;
}
# Must be a header
# ----------------
if ( substr($line,1,1) ne " " ) {
print "<li> <a href=\#$tokens[0]$tokens[1] > $line </a></li>\n";
next HLINE;
}
} # not blank
} # while
print "</ul>\n";
# Do body
# -------
} else {
$man = 0; # where NAME has beeing found yet
LINE: while (<>) {
$line = $_;
chomp $line;
@tokens = split " ", "$line";
if ( "$tokens[0]" eq "NAME" ) {
$man = 1;
print "<h2> <a name=$tokens[0] </a> $line </h2>\n";
print "<pre>\n";
next LINE;
}
$man = 0 if ( "$tokens[0]" eq "<RC>" );
next LINE unless($man);
# Must be a header
# ----------------
if ( substr($line,1,1) ne " " ) {
print "</pre>\n";
print "<h2> <a name=$tokens[0]$tokens[1] </a> $line </h2>\n";
print "<pre>\n";
next LINE;
}
print "$line\n";
}
print "</pre>\n";
}