-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenhtml
executable file
·58 lines (54 loc) · 1.17 KB
/
genhtml
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
#!/bin/sh -e
# This script takes a txt file and generates the appropriate html file
exec < "$1"
read -r title
./htmlheader "$title"
printf '%s\n' "<h1>$title</h1>"
while IFS= read -r line; do
case "$line" in
'')
if [ "$multiline" ]; then
printf '%s\n' '</pre>'
unset -v multiline
fi
;;
.img' '*) # syntax: .img src [alt...]
line=${line#.img }; src=${line%% *}; alt=${line#* };
printf '%s\n' "<a href=\"$src\"><img src=\"$src\" alt=\"$alt\"></a>"
;;
.link' '*) # syntax: .link link
link=${line#.link }
printf '%s\n' "<p><a href=\"$link\">$link</a></p>"
;;
.section' '*) # syntax: .section section
printf '%s\n' "<h2 id=\"${line#.section }\">${line#.section }</h2>"
;;
.index)
sed -n '
1i <h2>Contents</h2><ul>
/^\.section / {
s/^\.section //
s|.*|<li><a href="#&">&</a></li>|p
}
$a </ul>
' < "$1"
;;
*'\')
if [ "$multiline" ]; then
printf '%s\n' "${line%'\'}"
else
multiline=1
printf '%s\n' "<pre>${line%'\'}"
fi
;;
*)
if [ "$multiline" ]; then
printf '%s\n' "$line</pre>"
else
printf '%s\n' "<p>$line</p>"
fi
unset -v multiline
;;
esac
done
./htmlfooter