annotate help/generate.sh @ 496:fb95d70c80d5

More help
author Chris Cannam
date Fri, 19 Aug 2011 16:30:43 +0100
parents e6141a238811
children 21aa41b62c3a
rev   line source
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@496 24 s/\*([\w"][^\*]+)\*/<b>$1<\/b>/gs;
Chris@494 25 s/"([\w])/&ldquo;$1/gs;
Chris@494 26 s/([\w])"/$1&rdquo;/gs;
Chris@495 27 s/^\#([^\s]+)$/<center><img src="images\/$1.png"><\/center>/gm;
Chris@494 28 s/\n-+\n/\n/gs;
Chris@494 29 s/\n\n([^\n])/\n\n<p>$1/gs;
Chris@494 30 s/^\n*([^<\n])/\n<p>$1/gs;
Chris@494 31 s/^\n*(<[^p])/\n<p>$1/gs;
Chris@494 32 s/([^\n])\n\n/$1<\/p>\n\n/gs;
Chris@494 33 s/([^>\n])\n*$/$1<\/p>\n\n/gs;
Chris@496 34 s/\[\[([^\|]*)\|([^\]]*)\]\]/<a href="a-$1.html">$2<\/a>/gs;
Chris@494 35 s/\[\[([^\|\]]*)\]\]/<a href="$1">$1<\/a>/gs;
Chris@494 36 s/\b_([^_]+)_\b/<i>$1<\/i>/gs;
Chris@494 37 s/@(\w[^@]+)@/<code>$1<\/code>/gs;
Chris@494 38 s/---/&mdash;/gs;
Chris@494 39 s/--/&ndash;/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@495 51 pcat="$category"
Chris@494 52 fi
Chris@494 53
Chris@494 54 grep '<h2>' "$out" | sed "s|<h2>|<p><a href=\"$out\">|" | sed 's/<\/h2>/<\/a><\/p>/' >> topics.html
Chris@494 55
Chris@494 56 done
Chris@494 57