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
|
#!/bin/rc -e
rfork E
# index -- add ids to headings and print index to stderr
flagfmt=s
args='[file ...]'
if(! ifs=() eval `{aux/getflags $*}){
aux/usage
exit usage
}
fn source{
if(! ~ $#* 0)
cat $*
if not
cat
}
source $* | awk '
/<h[0-9]>.*<\/h[0-9]/ {
heading($0)
next
}
/<h[0-9]>/ {
open = 1
s = $0
next
}
open && /<\/h[0-9]>/ {
open = 0
s = s "\n" $0
heading(s)
next
}
open { s = s " " $0; next }
{ print }
function heading(s) {
i = s
sub("^.*<h[0-9]>", "", i)
sub("</h[0-9]>.*$", "", i)
i = toascii(i)
sub("^<h[0-9]", "& id=\"" i "\"", s)
print s
if (!ENVIRON["flags"]) { # if not silent mode
sub("^<h", "", s)
sub(" id=\"", " ", s)
sub("\">", " ", s)
sub("<\/h[0-9]>$", "", s)
print s > "/dev/stderr"
}
}
function toascii(s) {
s = tolower(s)
gsub("[ÀÁÂÃÄÅàáâãäå]", "a", s)
gsub("[Ææ]", "ae", s)
gsub("[Çç]", "c", s)
gsub("[Ðð]", "dh", s)
gsub("[ÈÉÊËèéêë]", "e", s)
gsub("[ÌÍÎÏìíîï]", "i", s)
gsub("[Ññ]", "n", s)
gsub("[ÒÓÔÕÖØòóôõöø]", "o", s)
gsub("[ß]", "ss", s)
gsub("[Þþ]", "th", s)
gsub("[ÙÚÛÜùúûü]", "u", s)
gsub("[×]", "x", s)
gsub("[Ýýÿ]", "y", s)
gsub("[/]", "-", s)
gsub("[ \n]+\\+[ \n]+", "+", s)
gsub("[ \n]+=[ \n]+", "=", s)
gsub("[ \n]+", "-", s)
gsub("[^=-+a-z0-9_ ]", "", s)
gsub("-+", "-", s)
return s
}
'
|