]> git.plutz.net Git - clickslide/blob - clickslide.sh
image embedding (for inline style bg images)
[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     ### Image embedding for Inline styles
27     while expr "$tag" : '.*<[^>]*style="[^"]*url("\?[^)]\+\.\(png\|jpg\|jpeg\|gif\|svg\)"\?)'; do
28       pre="${tag%%url(*)*}"
29       post="${tag#*url(*)}"
30       file="${tag#${pre}url(}" file="${file%)$post}"
31       file="${file#"}" file="${file%"}"
32       echo Inlining Image "$file" >&2
33       if [ -r "$file" ]; then
34         tag="${pre}url('data:image/${file##*.};base64,$(base64 <"${file}" |tr -d \\n)')${post}"
35       fi
36     done >/dev/null
37
38     ### Tag Processing
39     case $tag in
40       *\<head\>*|\*\<head\ *\>)  # Inline styles into head
41         printf '%s<meta name="viewport" content="width=device-width">
42                 <style type="text/css"><!--\n' "${tag%${tag#*<head*>}}"
43         cat "${0%/*}/clickslide.css"
44         printf '\n--></style>%s' "${tag#*<head*>}"
45         tag='' depth=$((depth + 1))
46         ;;
47       *\<slide\ *id=\"?*\"*\>*)  # Count slide id, insert "next" button
48         prev="$next"
49         next="${tag#*<slide }" next="${next#*id=\"}" next="${next%\"*}"
50         next="autoslide${idoff}"
51         idoff="$((idoff + 1))"
52         printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
53           "${tag%<slide *}" "$next" "$idoff" "$next" "${tag#*<slide }"
54         tag='' depth=$((depth + 1))
55         ;;
56       *\<slide\ *\>*|*\<slide\>*)
57         prev="$next"
58         next="autoslide${idoff}"
59         idoff="$((idoff + 1))"
60         printf '%s<a class="nextslide" href="#%s">next</a><div class="slide" count="%i" id="%s" %s' \
61           "${tag%<slide*}" "$next" "$idoff" "$next" "${tag#*<slide}"
62         tag='' depth=$((depth + 1))
63         ;;
64       *\</slide\>*)  # Insert "previous" button
65         printf '%s</div><a class="prevslide" href="#%s">previous</a>%s' \
66           "${tag%</slide>*}" "$prev" "${tag#*</slide>}"
67         tag='' depth=$((depth - 1))
68         ;;
69       *\<body*\>*)  # Insert toplevel link
70         printf '%s<a href="#" class="toplevel">overview</a>' "$tag"
71         tag='' depth=$((depth + 1))
72         ;;
73       *\</body*\>*)  # Insert total slide count
74         printf '<span class="count">%i</span>%s' "$idoff" "$tag"
75         tag='' depth=$((depth - 1))
76         ;;
77       *\<*class=\"uncover\"*\>*)  # Insert checkboxes in "uncover" lists
78         #printf '%s<li></li>' "$tag"
79         printf '%s' "$tag"
80         tag='' depth=$((depth + 1))
81         ucdepth=$depth
82         ;;
83       *\</*\>*)
84         printf %s "$tag"
85         tag='' depth=$((depth - 1))
86         [ $depth -lt $ucdepth ] && ucdepth=-1
87         ;;
88       *\<*\>*)
89         if [ $ucdepth = $depth ]; then
90           printf '%s<input type="checkbox" class="uncover"/><%s' "${tag%<*}" "${tag#*<}"
91         else
92           printf %s "$tag"
93         fi
94         [ "${tag}" = "${tag%/>}" ] && depth=$((depth + 1))
95         tag=''
96         ;;
97       *) :
98         ;;
99     esac
100   done
101 }