diff options
-rwxr-xr-x | jimmy | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/jimmy b/jimmy index ed87dc1..a85c448 100755 --- a/jimmy +++ b/jimmy | |||
@@ -69,21 +69,31 @@ gmi() { | |||
69 | ### Filters | 69 | ### Filters |
70 | 70 | ||
71 | filter_buff() { | 71 | filter_buff() { |
72 | case "$1" in | 72 | f="filter_buff_$to" |
73 | (html) | 73 | if type "$f" | grep -q function |
74 | sed 's#\*\([^*]*\)\*#<b>\1</b>#g' | # *strong* | 74 | then "$f" | sed -e "s/$nl/\n/g" -e "s/$sp/ /g" # fix whitespace |
75 | sed 's#_\([^_]*\)_#<i>\1</i>#g' | # _emph_ | 75 | else sed -e "s/$nl/\n/g" -e "s/$sp/ /g" |
76 | sed 's#`\([^`]*\)`#<code>\1</code>#' | # `code` | 76 | fi |
77 | cat | ||
78 | ;; | ||
79 | (*) cat ;; | ||
80 | esac | ||
81 | } | 77 | } |
82 | 78 | ||
83 | filter_line() { | 79 | filter_line() { |
84 | case "$1" in | 80 | f="filter_line_$to" |
85 | (*) cat ;; | 81 | if type "$f" | grep -q function |
86 | esac | 82 | then printf '%s\n' "$*" | "$f" |
83 | else printf '%s\n' "$*" | ||
84 | fi | ||
85 | } | ||
86 | |||
87 | filter_line_html() { | ||
88 | # s/// : escape <, >, & from html | ||
89 | # s### : *bold*, _italic_, `code` | ||
90 | sed -e 's/&/\&/g' \ | ||
91 | -e 's/</\</g' \ | ||
92 | -e 's/>/\>/g' \ | ||
93 | -e 's#\*\([^*]*\)\*#<b>\1</b>#g' \ | ||
94 | -e 's#_\([^_]*\)_#<i>\1</i>#g' \ | ||
95 | -e 's#`\([^`]*\)`#<code>\1</code>#' | ||
96 | |||
87 | } | 97 | } |
88 | 98 | ||
89 | ### Processing | 99 | ### Processing |
@@ -92,15 +102,13 @@ filter_line() { | |||
92 | 102 | ||
93 | pushline() { | 103 | pushline() { |
94 | tag="$1"; shift | 104 | tag="$1"; shift |
95 | printf "$(eval echo "\$fmtline_$tag")" "$@" | | 105 | printf "$(eval echo "\$fmtline_$tag")" "$@" >> "$buff" |
96 | filter_line "$to" >> "$buff" | ||
97 | } | 106 | } |
98 | 107 | ||
99 | bufprint() { | 108 | bufprint() { |
100 | b="$(cat<"$buff"|filter_buff "$to")" | 109 | b="$(cat<"$buff" | filter_buff)" |
101 | test -n "$b" || return | 110 | test -n "$b" || return |
102 | printf "$(eval echo "\$fmtbuff_$1")" "$b" | | 111 | printf "$(eval echo "\$fmtbuff_$1")" "$b" | filter_buff |
103 | sed -e "s/$nl/\n/g" -e "s/$sp/ /g" # fix whitespace | ||
104 | : > "$buff" | 112 | : > "$buff" |
105 | } | 113 | } |
106 | 114 | ||
@@ -111,7 +119,7 @@ process() { | |||
111 | do | 119 | do |
112 | if $verbatim && test "$sigil" != '```' | 120 | if $verbatim && test "$sigil" != '```' |
113 | then | 121 | then |
114 | pushline verb "$sigil $line" | 122 | pushline verb "$(filter_line "$sigil $line")" |
115 | continue | 123 | continue |
116 | fi | 124 | fi |
117 | 125 | ||
@@ -158,8 +166,8 @@ process() { | |||
158 | fi | 166 | fi |
159 | 167 | ||
160 | if test "$curr" = link | 168 | if test "$curr" = link |
161 | then pushline "$curr" "$url" "$title" | 169 | then pushline "$curr" "$url" "$(filter_line "$title")" |
162 | else pushline "$curr" "$line" | 170 | else pushline "$curr" "$(filter_line "$line")" |
163 | fi | 171 | fi |
164 | done | 172 | done |
165 | 173 | ||