]> git.plutz.net Git - clickslide/commitdiff
previous/next link generation
authorPaul Hänsch <paul@plutz.net>
Fri, 1 Feb 2019 05:27:57 +0000 (06:27 +0100)
committerPaul Hänsch <paul@plutz.net>
Fri, 1 Feb 2019 05:27:57 +0000 (06:27 +0100)
autoslide.sh [new file with mode: 0755]

diff --git a/autoslide.sh b/autoslide.sh
new file mode 100755 (executable)
index 0000000..a7d08bc
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+last='' curr='' next=''
+idoff=1
+
+line="$(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
+      printf %s\\n "$tag"
+      break
+    fi
+    tag="${tag}
+"
+  else
+    # $line is shortened by segment added to $tag
+    line="${line#*>}"
+    tag="${tag}>"
+  fi
+
+  case $tag in
+    *\<slide\ *id=\"?*\"*\>*)
+      prev="$curr" curr="$next"
+      next="${tag#*<slide }"
+      next="${next#*id=\"}"
+      next="${next%\"*}"
+      printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
+        "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
+      tag=''
+      ;;
+    *\<slide\ *\>*)
+      prev="$curr" curr="$next"
+      next="autoslide${idoff}"
+      idoff="$((idoff + 1))"
+      printf '%s<a href="#%s">previous</a><a href="#%s">next</a><slide %s' \
+        "${tag%<slide *}" "$prev" "$next" "${tag#*<slide }"
+      tag=''
+      ;;
+    *\<*\>*)
+      printf %s "$tag"
+      tag=''
+      ;;
+    *) :
+      ;;
+  esac
+done