Chris@494
|
1 #!/bin/bash
|
Chris@494
|
2
|
Chris@494
|
3 css='<link rel="stylesheet" type="text/css" href="help.css"/>'
|
Chris@494
|
4 backlink='<p><a href="topics.html">Back to Topics</a></p>'
|
Chris@494
|
5
|
Chris@494
|
6 echo "$css" > topics.html
|
Chris@494
|
7 cat intro.html >> topics.html
|
Chris@494
|
8
|
Chris@494
|
9 pcat=""
|
Chris@494
|
10
|
Chris@494
|
11 for x in topics/*.txt ; do
|
Chris@494
|
12
|
Chris@494
|
13 b=`basename "$x" .txt`
|
Chris@494
|
14 out="a-$b.html"
|
Chris@494
|
15
|
Chris@494
|
16 echo "$css" > "$out"
|
Chris@494
|
17 echo "$backlink<hr>" >> "$out"
|
Chris@494
|
18
|
Chris@494
|
19 cat "$x" | perl -e '
|
Chris@494
|
20 $_ = join "", <>;
|
Chris@494
|
21 s/^{[\w\s]+}//s;
|
Chris@494
|
22 s/^(\s*)([A-Za-z][^\n]*)/$1<h2>$2<\/h2>/s;
|
Chris@494
|
23 s/^\s+\*\s+(.*)$/<ul><li>$1<\/li><\/ul>/gm;
|
Chris@494
|
24 s/"([\w])/“$1/gs;
|
Chris@494
|
25 s/([\w])"/$1”/gs;
|
Chris@494
|
26 s/^\#([^\s]+)$/<center><img src="images\/$1"><\/center>/gm;
|
Chris@494
|
27 s/\n-+\n/\n/gs;
|
Chris@494
|
28 s/\n\n([^\n])/\n\n<p>$1/gs;
|
Chris@494
|
29 s/^\n*([^<\n])/\n<p>$1/gs;
|
Chris@494
|
30 s/^\n*(<[^p])/\n<p>$1/gs;
|
Chris@494
|
31 s/([^\n])\n\n/$1<\/p>\n\n/gs;
|
Chris@494
|
32 s/([^>\n])\n*$/$1<\/p>\n\n/gs;
|
Chris@494
|
33 s/\[\[([^\|]*)\|([^\]]*)\]\]/<a href="$1">$2<\/a>/gs;
|
Chris@494
|
34 s/\[\[([^\|\]]*)\]\]/<a href="$1">$1<\/a>/gs;
|
Chris@494
|
35 s/\b_([^_]+)_\b/<i>$1<\/i>/gs;
|
Chris@494
|
36 s/\*(\w[^\*]+)\*/<b>$1<\/b>/gs;
|
Chris@494
|
37 s/@(\w[^@]+)@/<code>$1<\/code>/gs;
|
Chris@494
|
38 s/---/—/gs;
|
Chris@494
|
39 s/--/–/gs;
|
Chris@494
|
40 s/<p><h2>/<h2>/gs;
|
Chris@494
|
41 s/<\/h2><\/p>/<\/h2>/gs;
|
Chris@494
|
42 print;
|
Chris@494
|
43 ' >> "$out"
|
Chris@494
|
44
|
Chris@494
|
45 echo "<hr>$backlink" >> "$out"
|
Chris@494
|
46
|
Chris@494
|
47 category=`grep '^{.*}$' "$x" | sed 's/[{}]//g'`
|
Chris@494
|
48
|
Chris@494
|
49 if [ "$category" != "$pcat" ]; then
|
Chris@494
|
50 echo "<h3>$category</h3>" >> topics.html
|
Chris@494
|
51 fi
|
Chris@494
|
52
|
Chris@494
|
53 grep '<h2>' "$out" | sed "s|<h2>|<p><a href=\"$out\">|" | sed 's/<\/h2>/<\/a><\/p>/' >> topics.html
|
Chris@494
|
54
|
Chris@494
|
55 done
|
Chris@494
|
56
|