X-Git-Url: http://git.plutz.net/?p=clickslide;a=blobdiff_plain;f=clickslide.sh;h=750b6b0c05380c918ab8426f61cc6ae21ea46956;hp=dcb01db6dc4b3264d00cfa3ee5dca6b7d2863c5c;hb=HEAD;hpb=f3d10e74c2c37195dc5fac09af5ff02d13307bf3
diff --git a/clickslide.sh b/clickslide.sh
index dcb01db..750b6b0 100755
--- a/clickslide.sh
+++ b/clickslide.sh
@@ -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
@@ -28,10 +42,21 @@ depth=0 ucdepth=-1
pre="${tag%%url(*)*}"
post="${tag#*url(*)}"
file="${tag#${pre}url(}" file="${file%)$post}"
- file="${file#"}" file="${file%"}"
+ 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" : '.*]*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}url('data:image/${file##*.};base64,$(base64 <"${file}" |tr -d \\n)')${post}"
+ tag="${pre}src=\"data:image/${file##*.};base64,$(_base64 "${file}")\"${post}"
fi
done >/dev/null
@@ -39,6 +64,7 @@ depth=0 ucdepth=-1
case $tag in
*\