]> git.plutz.net Git - clickslide/blobdiff - clickslide.sh
styling of lists
[clickslide] / clickslide.sh
index ddc94c37ef79e44753e54fc71b670f1aef45d0f2..750b6b0c05380c918ab8426f61cc6ae21ea46956 100755 (executable)
@@ -3,15 +3,29 @@
 prev='' next='' idoff=0
 depth=0 ucdepth=-1
 
+_base64() {
+  # busybox does not ship base64, only uuencode. Other platforms might need base64 instead
+  if which uuencode >/dev/null; then
+    uuencode -m - <"$1" \
+    | sed '1d; :X;$!{N;bX;}; s;\n;;g; s;=\+;;g;'
+  elif which busybox >/dev/null; then
+    busybox uuencode -m - <"$1" \
+    | sed '1d; :X;$!{N;bX;}; s;\n;;g; s;=\+;;g;'
+  else
+    base64 <"$1" \
+    | sed ':X;$!{N;bX;}; s;\n;;g; s;=\+;;g;'
+  fi
+}
+
 { "${0%/*}"/cgilite/html-sh.sed || cat; } \
 | {
-  line="$(line)"
+  read -r line
   while :; do 
     tag="${tag}${line%%>*}"
   
     if [ "$line" = "${line%%>*}" ]; then
       # $line did not contain ">" and thus was added to $tag entirely
-      if ! line="$(line)"; then
+      if ! read -r line; then
         printf %s\\n "$tag"
         break
       fi
@@ -22,16 +36,41 @@ depth=0 ucdepth=-1
       line="${line#*>}"
       tag="${tag}>"
     fi
-  
+
+    ### Image embedding for Inline styles
+    while expr "$tag" : '.*<[^>]*style="[^"]*url("\?[^)]\+\.\(png\|jpg\|jpeg\|gif\|svg\)"\?)'; do
+      pre="${tag%%url(*)*}"
+      post="${tag#*url(*)}"
+      file="${tag#${pre}url(}" file="${file%)$post}"
+      file="${file#\"}" file="${file%\"}"
+      echo Inlining Background Image "$file" >&2
+      if [ -r "$file" ]; then
+        tag="${pre}url('data:image/${file##*.};base64,$(_base64 "$file")')${post}"
+      fi
+    done >/dev/null
+
+    ### Image embedding for Image tags
+    while expr "$tag" : '.*<img [^>]*src="[^"]\+\.\(png\|jpg\|jpeg\|gif\|svg\)"'; do
+      pre="${tag%%src=\"*\"*}"
+      post="${tag#*src=\"*\"}"
+      file="${tag#${pre}src=\"}" file="${file%\"$post}"
+      echo Inlining Image "$file" >&2
+      if [ -r "$file" ]; then
+        tag="${pre}src=\"data:image/${file##*.};base64,$(_base64 "${file}")\"${post}"
+      fi
+    done >/dev/null
+
+    ### Tag Processing
     case $tag in
-      *\<head\>*|\*\<head\ *\>)
+      *\<head\>*|\*\<head\ *\>)  # Inline styles into head
         printf '%s<meta name="viewport" content="width=device-width">
+                <meta charset="UTF-8">
                 <style type="text/css"><!--\n' "${tag%${tag#*<head*>}}"
         cat "${0%/*}/clickslide.css"
         printf '\n--></style>%s' "${tag#*<head*>}"
         tag='' depth=$((depth + 1))
         ;;
-      *\<slide\ *id=\"?*\"*\>*)
+      *\<slide\ *id=\"?*\"*\>*)  # Count slide id, insert "next" button
         prev="$next"
         next="${tag#*<slide }" next="${next#*id=\"}" next="${next%\"*}"
         next="autoslide${idoff}"
@@ -48,25 +87,25 @@ depth=0 ucdepth=-1
           "${tag%<slide*}" "$next" "$idoff" "$next" "${tag#*<slide}"
         tag='' depth=$((depth + 1))
         ;;
-      *\</slide\>*)
+      *\</slide\>*)  # Insert "previous" button
         printf '%s</div><a class="prevslide" href="#%s">previous</a>%s' \
           "${tag%</slide>*}" "$prev" "${tag#*</slide>}"
         tag='' depth=$((depth - 1))
         ;;
-      *\<*class=\"uncover\"*\>*)
-        #printf '%s<li></li>' "$tag"
-        printf '%s' "$tag"
-        tag='' depth=$((depth + 1))
-        ucdepth=$depth
-        ;;
-      *\<body*\>*)
+      *\<body*\>*)  # Insert toplevel link
         printf '%s<a href="#" class="toplevel">overview</a>' "$tag"
         tag='' depth=$((depth + 1))
         ;;
-      *\</body*\>*)
+      *\</body*\>*)  # Insert total slide count
         printf '<span class="count">%i</span>%s' "$idoff" "$tag"
         tag='' depth=$((depth - 1))
         ;;
+      *\<*class=\"uncover\"*\>*)  # Insert checkboxes in "uncover" lists
+        #printf '%s<li></li>' "$tag"
+        printf '%s' "$tag"
+        tag='' depth=$((depth + 1))
+        ucdepth=$depth
+        ;;
       *\</*\>*)
         printf %s "$tag"
         tag='' depth=$((depth - 1))