]> git.plutz.net Git - clickslide/blob - clickslide.sh
including example, developing styles
[clickslide] / clickslide.sh
1 #!/bin/sh
2
3 prev='' next='' idoff=0
4 depth=0 ucdepth=-1
5
6 { "${0%/*}"/cgilite/html-sh.sed || cat; } \
7 | {
8   line="$(line)"
9   while :; do 
10     tag="${tag}${line%%>*}"
11   
12     if [ "$line" = "${line%%>*}" ]; then
13       # $line did not contain ">" and thus was added to $tag entirely
14       if ! line="$(line)"; then
15         printf %s\\n "$tag"
16         break
17       fi
18       tag="${tag}
19   "
20     else
21       # $line is shortened by segment added to $tag
22       line="${line#*>}"
23       tag="${tag}>"
24     fi
25   
26     case $tag in
27       *\<head\>*|\*\<head\ *\>)
28         printf '%s<meta name="viewport" content="width=device-width">
29                 <style type="text/css"><!--\n' "${tag%${tag#*<head*>}}"
30         cat "${0%/*}/clickslide.css"
31         printf '\n--></style>%s' "${tag#*<head*>}"
32         tag='' depth=$((depth + 1))
33         ;;
34       *\<slide\ *id=\"?*\"*\>*)
35         prev="$next"
36         next="${tag#*<slide }" next="${next#*id=\"}" next="${next%\"*}"
37         next="autoslide${idoff}"
38         idoff="$((idoff + 1))"
39         printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
40           "${tag%<slide *}" "$next" "$idoff" "$next" "${tag#*<slide }"
41         tag='' depth=$((depth + 1))
42         ;;
43       *\<slide\ *\>*|*\<slide\>*)
44         prev="$next"
45         next="autoslide${idoff}"
46         idoff="$((idoff + 1))"
47         printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
48           "${tag%<slide*}" "$next" "$idoff" "$next" "${tag#*<slide}"
49         tag='' depth=$((depth + 1))
50         ;;
51       *\</slide\>*)
52         printf '%s</div><a class="prevslide" href="#%s">previous</a>%s' \
53           "${tag%</slide>*}" "$prev" "${tag#*</slide>}"
54         tag='' depth=$((depth - 1))
55         ;;
56       *\<*class=\"uncover\"*\>*)
57         #printf '%s<li></li>' "$tag"
58         printf '%s' "$tag"
59         tag='' depth=$((depth + 1))
60         ucdepth=$depth
61         ;;
62       *\<body*\>*)
63         printf '%s<a href="#" class="toplevel">overview</a>' "$tag"
64         tag='' depth=$((depth + 1))
65         ;;
66       *\</body*\>*)
67         printf '<span class="count">%i</span>%s' "$idoff" "$tag"
68         tag='' depth=$((depth - 1))
69         ;;
70       *\</*\>*)
71         printf %s "$tag"
72         tag='' depth=$((depth - 1))
73         [ $depth -lt $ucdepth ] && ucdepth=-1
74         ;;
75       *\<*\>*)
76         if [ $ucdepth = $depth ]; then
77           printf '%s<input type="checkbox" class="uncover"/><%s' "${tag%<*}" "${tag#*<}"
78         else
79           printf %s "$tag"
80         fi
81         [ "${tag}" = "${tag%/>}" ] && depth=$((depth + 1))
82         tag=''
83         ;;
84       *) :
85         ;;
86     esac
87   done
88 }