]> git.plutz.net Git - clickslide/blob - autoslide.sh
use shorthand html
[clickslide] / autoslide.sh
1 #!/bin/sh
2
3 last='' curr='' next=''
4 idoff=1
5
6 "${0%/*}"/cgilite/html-sh.sed | {
7   line="$(line)"
8   while :; do 
9     tag="${tag}${line%%>*}"
10   
11     if [ "$line" = "${line%%>*}" ]; then
12       # $line did not contain ">" and thus was added to $tag entirely
13       if ! line="$(line)"; then
14         printf %s\\n "$tag"
15         break
16       fi
17       tag="${tag}
18   "
19     else
20       # $line is shortened by segment added to $tag
21       line="${line#*>}"
22       tag="${tag}>"
23     fi
24   
25     case $tag in
26       *\<slide\ *id=\"?*\"*\>*)
27         prev="$curr" curr="$next"
28         next="${tag#*<slide }"
29         next="${next#*id=\"}"
30         next="${next%\"*}"
31         printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
32           "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
33         tag=''
34         ;;
35       *\<slide\ *\>*)
36         prev="$curr" curr="$next"
37         next="autoslide${idoff}"
38         idoff="$((idoff + 1))"
39         printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
40           "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
41         tag=''
42         ;;
43       *\<*\>*)
44         printf %s "$tag"
45         tag=''
46         ;;
47       *) :
48         ;;
49     esac
50   done
51 }