From 54e07f822b463c8d461fef254213f83c59d82810 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 1 Feb 2024 23:52:57 -0600 Subject: Refactor for interleaved shell commands and text --- st.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 st.sh (limited to 'st.sh') diff --git a/st.sh b/st.sh new file mode 100644 index 0000000..8274526 --- /dev/null +++ b/st.sh @@ -0,0 +1,47 @@ +### 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,$,,' +} + +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