From 7ee6c3a206d202d97c3aad98175e49787f1e40d1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 6 Feb 2024 00:10:44 -0600 Subject: rename st.sh to html.st.sh --- html.st.sh | 41 +++++++++++++++++++++++++++++++++++++++++ st.sh | 47 ----------------------------------------------- 2 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 html.st.sh delete mode 100644 st.sh 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 @@ +# -*- sh -*- +html_fix() { + sed -E \ + -e 's#([^\\]|^)\1\&#g' \ + -e 's#([^\\]|^)<#\1\<#g' \ + -e 's#([^\\]|^)>#\1\>#g' \ + -e 's#\\([&<>])#\1#g' +} + +html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT] + tag="$1"; attrs= ; text= + shift + for arg + do + case "$arg" in + (*=*) attrs="$attrs ${arg%%=*}=${arg#*=}"; shift ;; + (*) break ;; + esac + done + + printf '<%s%s>%s' "$tag" "$attrs" + handle_input "$@" | + sed -E \ + -e '$s#[ ]([.!-;:,.?])$#'"$tag"'>\1#' -e t \ + -e '$s,$,'"$tag"'>,' +} + +for el in h1 h2 h3 p a blockquote ul ol li em strong b i dl dt dd +do + alias $el="html_el $el" +done + +alias @=html_el + +code() { + in="$(handle_input "$@")" + if test $? -ne 0 + then html_el code "$@" # runs thru input twice, meh + else echo "
$in
"
+ fi
+}
diff --git a/st.sh b/st.sh
deleted file mode 100644
index 8274526..0000000
--- a/st.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-### st.sh
-
-# utilities
-echo()(printf '%s\n' "$*")
-
-handle_input() { # handle_input "$@"
- # handle input --- args or stdin
- test -n "$1" && printf '%s' "$*"
- if read -r first_line
- then echo "$first_line"; cat
- else echo
- fi
-}
-
-# authoring commands
-nb() { # comment mechanism
- :
-}
-
-# html
-attr(){ # attr [NAME|VALUE] ATTR_STRING
- case "$1" in
- (name) echo "${2%%=*}" ;;
- (value) echo "${2#*=}" ;;
- esac
-}
-
-html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT]
- tag="$1"; attrs= ; text=
- shift
- for arg
- do
- case "$arg" in
- (*=*) attrs="$attrs ${arg%%=*}=${arg#*=}"; shift ;;
- (*) break ;;
- esac
- done
-
- printf '<%s%s>%s' "$tag" "$attrs"
- handle_input "$@" | sed '$s,$,'"$tag"'>,'
-}
-
-alias p='html_el p'
-alias a='html_el a'
-alias h1='html_el h1'
-alias blockquote='html_el blockquote'
-alias bq=blockquote
--
cgit 1.4.1-21-gabe81