diff options
author | Case Duckworth | 2024-02-01 23:52:57 -0600 |
---|---|---|
committer | Case Duckworth | 2024-02-01 23:52:57 -0600 |
commit | 54e07f822b463c8d461fef254213f83c59d82810 (patch) | |
tree | f5f8d7e6375653113b6aaef2e12905b4a7d26334 /st.sh | |
parent | uhh (diff) | |
download | subtext-54e07f822b463c8d461fef254213f83c59d82810.tar.gz subtext-54e07f822b463c8d461fef254213f83c59d82810.zip |
Refactor for interleaved shell commands and text
Diffstat (limited to 'st.sh')
-rw-r--r-- | st.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/st.sh b/st.sh new file mode 100644 index 0000000..8274526 --- /dev/null +++ b/st.sh | |||
@@ -0,0 +1,47 @@ | |||
1 | ### st.sh | ||
2 | |||
3 | # utilities | ||
4 | echo()(printf '%s\n' "$*") | ||
5 | |||
6 | handle_input() { # handle_input "$@" | ||
7 | # handle input --- args or stdin | ||
8 | test -n "$1" && printf '%s' "$*" | ||
9 | if read -r first_line | ||
10 | then echo "$first_line"; cat | ||
11 | else echo | ||
12 | fi | ||
13 | } | ||
14 | |||
15 | # authoring commands | ||
16 | nb() { # comment mechanism | ||
17 | : | ||
18 | } | ||
19 | |||
20 | # html | ||
21 | attr(){ # attr [NAME|VALUE] ATTR_STRING | ||
22 | case "$1" in | ||
23 | (name) echo "${2%%=*}" ;; | ||
24 | (value) echo "${2#*=}" ;; | ||
25 | esac | ||
26 | } | ||
27 | |||
28 | html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT] | ||
29 | tag="$1"; attrs= ; text= | ||
30 | shift | ||
31 | for arg | ||
32 | do | ||
33 | case "$arg" in | ||
34 | (*=*) attrs="$attrs ${arg%%=*}=${arg#*=}"; shift ;; | ||
35 | (*) break ;; | ||
36 | esac | ||
37 | done | ||
38 | |||
39 | printf '<%s%s>%s' "$tag" "$attrs" | ||
40 | handle_input "$@" | sed '$s,$,</'"$tag"'>,' | ||
41 | } | ||
42 | |||
43 | alias p='html_el p' | ||
44 | alias a='html_el a' | ||
45 | alias h1='html_el h1' | ||
46 | alias blockquote='html_el blockquote' | ||
47 | alias bq=blockquote | ||