diff options
author | Case Duckworth | 2024-02-06 00:10:44 -0600 |
---|---|---|
committer | Case Duckworth | 2024-02-06 00:10:44 -0600 |
commit | 7ee6c3a206d202d97c3aad98175e49787f1e40d1 (patch) | |
tree | 582945ffe16c494cdebbd6ff42af45a334ff75b5 | |
parent | Slight tweak to remove spurious variable (diff) | |
download | subtext-7ee6c3a206d202d97c3aad98175e49787f1e40d1.tar.gz subtext-7ee6c3a206d202d97c3aad98175e49787f1e40d1.zip |
rename st.sh to html.st.sh
-rw-r--r-- | html.st.sh | 41 | ||||
-rw-r--r-- | st.sh | 47 |
2 files changed, 41 insertions, 47 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 -*- | ||
2 | html_fix() { | ||
3 | sed -E \ | ||
4 | -e 's#([^\\]|^)&#\1\&#g' \ | ||
5 | -e 's#([^\\]|^)<#\1\<#g' \ | ||
6 | -e 's#([^\\]|^)>#\1\>#g' \ | ||
7 | -e 's#\\([&<>])#\1#g' | ||
8 | } | ||
9 | |||
10 | html_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 | |||
28 | for el in h1 h2 h3 p a blockquote ul ol li em strong b i dl dt dd | ||
29 | do | ||
30 | alias $el="html_el $el" | ||
31 | done | ||
32 | |||
33 | alias @=html_el | ||
34 | |||
35 | code() { | ||
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 | } | ||
diff --git a/st.sh b/st.sh deleted file mode 100644 index 8274526..0000000 --- a/st.sh +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
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 | ||