*) return 1 ;;
esac
+# TODO: Support .uncover for other than list items
+
printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
cat <<-EOF
# 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
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))"
"${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))"
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=''
;;
*) :