]> git.plutz.net Git - shellwiki/commitdiff
simplified depth counting (like in original clickslide)
authorPaul Hänsch <paul@plutz.net>
Sat, 26 Sep 2026 18:27:20 +0000 (20:27 +0200)
committerPaul Hänsch <paul@plutz.net>
Sat, 26 Sep 2026 18:27:20 +0000 (20:27 +0200)
handlers/70_slideshow.sh

index 15349ccaf927c1c3db12436b13f78223a152e1b7..04f88b93bd00a4dd197c71cc691df38668705d7f 100755 (executable)
@@ -19,6 +19,8 @@ case $PATH_INFO in
   *) return 1 ;;
 esac
 
+# TODO: Support .uncover for other than list items
+
 printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
 
 cat <<-EOF
@@ -35,7 +37,6 @@ wiki "$page" | {
   # slide previous ID, slide current ID, slide number
   sl_pre='' sl_cur='' sl_num=0
   depth=0 ucdepth=-1
-  stack=''
   printf '<a href="#" class="toplevel">overview</a>'
 
   # loop over each tag in a line
@@ -60,8 +61,7 @@ wiki "$page" | {
 
     case $tag in
       *\<section\ class=\"h1*\"\ id=\"?*\"\>)  # Count slide id, insert "next" button
-        if [ "$stack" = "" ]; then
-          stack="${stack},section"
+        if [ "$depth" -eq 0 ]; then
           sl_pre="$sl_cur"
           sl_cur="${tag#*<section class=* id=\"}" sl_cur="${sl_cur%\">}"
           sl_num="$((sl_num + 1))"
@@ -70,22 +70,21 @@ wiki "$page" | {
             "${tag%<section *}" "$sl_cur" "$sl_num" "${tag#*<section class=\"}"
 
         else
-          stack="${stack},section"
           printf '%s' "$tag"
         fi
-        tag='' depth=$((depth + 1)) sldepth=$depth
+        depth=$((depth + 1))
+        tag=''
         ;;
       *\<section\ class=\"h2*\"\ id=\"?*\"\>)  # Count slide id, insert "next" button
         # *force* unwrapping from containing H1 section
-        if [ "$stack" = ",section" ]; then
+        if [ "$depth" -eq 1 ]; then
           printf '%s</section>\n<a class="prevslide" href="#%s">previous</a>' \
             "${tag%<section*}" "$sl_pre"
           tag="<section ${tag#*<section }"
-          stack="${stack%,section}"
+          depth="$((depth - 1))"
         fi
 
-        if [ "$stack" = "" ]; then
-          stack="${stack},section"
+        if [ "$depth" -eq 0 ]; then
           sl_pre="$sl_cur"
           sl_cur="${tag#*<section class=* id=\"}" sl_cur="${sl_cur%\">}"
           sl_num="$((sl_num + 1))"
@@ -93,51 +92,46 @@ wiki "$page" | {
           printf '%s<a class="nextslide" href="#%s">next</a>\n<section count="%i" class="slide %s' \
             "${tag%<section *}" "$sl_cur" "$sl_num" "${tag#*<section class=\"}"
         else
-          stack="${stack},section"
-          debug "$stack"
           printf '%s' "$tag"
         fi
-        tag='' depth=$((depth + 1)) sldepth=$depth
+        depth="$((depth + 1))"
+        tag=''
         ;;
       *\</section\>)  # Insert "previous" button
-        if [ "$stack" = ",section" ]; then
+        if [ "$depth" -eq 1 ]; then
           printf '%s\n<a class="prevslide" href="#%s">previous</a>' \
             "${tag}" "$sl_pre"
-        elif [ "$stack" = "" ]; then
-          :
+        elif [ "$depth" -eq 0 ]; then
+          :  # ignore "hanging" closing tag from unwrapped H1 section
         else
           printf %s "${tag}"
         fi
-        stack="${stack%,section}"
-        tag='' depth=$((depth - 1))
-        ;;
-      *\<*\ class=\"uncover\"*\>)  # Insert checkboxes in "uncover" lists
-        # printf '%s<li></li>' "$tag"
-        printf '%s' "$tag"
-        tag="${tag#*<}" tag="${tag%%[ >]*}"
-        stack="${stack},${tag}"
-        tag='' depth=$((depth + 1))
-        ucdepth=$((depth + 1))
+        depth=$((depth - 1))
+        tag=''
         ;;
       *\</*\>)
         printf %s "$tag"
-        stack="${stack%,*}"
-        tag='' depth=$((depth - 1))
+        depth=$((depth - 1))
         [ $depth -lt $ucdepth ] && ucdepth=-1
+        tag=''
         ;;
       *\<*/\>|*\<br\>|*\<hr\>|*\<img\ *\>)
         printf %s "$tag"
         tag=''
         ;;
-      *\<*\>*)
-        if [ $ucdepth = $depth ]; then
+      *\<*\ class=\"uncover\"*\>)  # Insert checkboxes in "uncover" lists
+        printf '%s' "$tag"
+        depth=$((depth + 1))
+        ucdepth=$((depth + 1))
+        tag=''
+        ;;
+      *\<*\>)
+        if [ $ucdepth -eq $depth ]; then
           printf '%s<input type="checkbox" class="uncover"/><%s' "${tag%<*}" "${tag#*<}"
         else
           printf %s "$tag"
         fi
-        [ "${tag}" = "${tag%/>}" ] && depth=$((depth + 1))
-        tag="${tag#*<}" tag="${tag%%[ >]*}"
-        stack="${stack},${tag}"
+        depth=$((depth + 1))
         tag=''
         ;;
       *) :