about summary refs log tree commit diff stats
path: root/html.st.sh
diff options
context:
space:
mode:
Diffstat (limited to 'html.st.sh')
-rw-r--r--html.st.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/html.st.sh b/html.st.sh new file mode 100644 index 0000000..ab4ab72 --- /dev/null +++ b/html.st.sh
@@ -0,0 +1,41 @@
1# -*- sh -*-
2html_fix() {
3 sed -E \
4 -e 's#([^\\]|^)&#\1\&#g' \
5 -e 's#([^\\]|^)<#\1\&lt;#g' \
6 -e 's#([^\\]|^)>#\1\&gt;#g' \
7 -e 's#\\([&<>])#\1#g'
8}
9
10html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT]
11 tag="$1"; attrs= ; text=
12 shift
13 for arg
14 do
15 case "$arg" in
16 (*=*) attrs="$attrs ${arg%%=*}=${arg#*=}"; shift ;;
17 (*) break ;;
18 esac
19 done
20
21 printf '<%s%s>%s' "$tag" "$attrs"
22 handle_input "$@" |
23 sed -E \
24 -e '$s#[ ]([.!-;:,.?])$#</'"$tag"'>\1#' -e t \
25 -e '$s,$,</'"$tag"'>,'
26}
27
28for el in h1 h2 h3 p a blockquote ul ol li em strong b i dl dt dd
29do
30 alias $el="html_el $el"
31done
32
33alias @=html_el
34
35code() {
36 in="$(handle_input "$@")"
37 if test $? -ne 0
38 then html_el code "$@" # runs thru input twice, meh
39 else echo "<pre><code>$in</code></pre>"
40 fi
41}