From 66c2899a46ddc7d88e39179f6b33173e1cf71935 Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Sat, 11 May 2024 22:06:54 -0500
Subject: Fix filters
---
jimmy | 48 ++++++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/jimmy b/jimmy
index ed87dc1..a85c448 100755
--- a/jimmy
+++ b/jimmy
@@ -69,21 +69,31 @@ gmi() {
### Filters
filter_buff() {
- case "$1" in
- (html)
- sed 's#\*\([^*]*\)\*#\1#g' | # *strong*
- sed 's#_\([^_]*\)_#\1#g' | # _emph_
- sed 's#`\([^`]*\)`#\1
#' | # `code`
- cat
- ;;
- (*) cat ;;
- esac
+ f="filter_buff_$to"
+ if type "$f" | grep -q function
+ then "$f" | sed -e "s/$nl/\n/g" -e "s/$sp/ /g" # fix whitespace
+ else sed -e "s/$nl/\n/g" -e "s/$sp/ /g"
+ fi
}
filter_line() {
- case "$1" in
- (*) cat ;;
- esac
+ f="filter_line_$to"
+ if type "$f" | grep -q function
+ then printf '%s\n' "$*" | "$f"
+ else printf '%s\n' "$*"
+ fi
+}
+
+filter_line_html() {
+ # s/// : escape <, >, & from html
+ # s### : *bold*, _italic_, `code`
+ sed -e 's/&/\&/g' \
+ -e 's/\</g' \
+ -e 's/>/\>/g' \
+ -e 's#\*\([^*]*\)\*#\1#g' \
+ -e 's#_\([^_]*\)_#\1#g' \
+ -e 's#`\([^`]*\)`#\1
#'
+
}
### Processing
@@ -92,15 +102,13 @@ filter_line() {
pushline() {
tag="$1"; shift
- printf "$(eval echo "\$fmtline_$tag")" "$@" |
- filter_line "$to" >> "$buff"
+ printf "$(eval echo "\$fmtline_$tag")" "$@" >> "$buff"
}
bufprint() {
- b="$(cat<"$buff"|filter_buff "$to")"
+ b="$(cat<"$buff" | filter_buff)"
test -n "$b" || return
- printf "$(eval echo "\$fmtbuff_$1")" "$b" |
- sed -e "s/$nl/\n/g" -e "s/$sp/ /g" # fix whitespace
+ printf "$(eval echo "\$fmtbuff_$1")" "$b" | filter_buff
: > "$buff"
}
@@ -111,7 +119,7 @@ process() {
do
if $verbatim && test "$sigil" != '```'
then
- pushline verb "$sigil $line"
+ pushline verb "$(filter_line "$sigil $line")"
continue
fi
@@ -158,8 +166,8 @@ process() {
fi
if test "$curr" = link
- then pushline "$curr" "$url" "$title"
- else pushline "$curr" "$line"
+ then pushline "$curr" "$url" "$(filter_line "$title")"
+ else pushline "$curr" "$(filter_line "$line")"
fi
done
--
cgit 1.4.1-21-gabe81