about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-01-21 00:06:21 -0600
committerCase Duckworth2024-01-21 00:06:21 -0600
commit7b853058f9d412ca896cb1fc94aa80978f02c5fd (patch)
treea8cfcb1110ebd6d3dc05d8cc31a57bb67133dc5d
downloadet-7b853058f9d412ca896cb1fc94aa80978f02c5fd.tar.gz
et-7b853058f9d412ca896cb1fc94aa80978f02c5fd.zip
Initial commit
-rwxr-xr-xet82
-rw-r--r--etlib.sh34
-rw-r--r--test.et31
3 files changed, 147 insertions, 0 deletions
diff --git a/et b/et new file mode 100755 index 0000000..06cbf4c --- /dev/null +++ b/et
@@ -0,0 +1,82 @@
1#!/bin/sh
2{ excitable="text" "exec" "awk" "-f" "$0" "$@"; } # -*- awk -*-
3# usage: et <file> | sh
4
5BEGIN {
6 xend = xend ? xend : "...xend..."
7 dend = dend ? dend : "...dend..."
8 # We shell out to sed for this because awk doesn't do capture groups ;-;
9 shellfix = "sed -E -e 's/`/\\\\`/g' " \
10 "-e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g' " \
11 "-e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'"
12 true = 1 ; false = 0
13 print "shellexpand()(eval \"$(echo \"cat<<'"xend"'\";cat;echo "xend")\")"
14 print "shellfix()(" shellfix ")"
15}
16
17end[endn] && $0 == end[endn] {
18 par = par "\n" end[endn--] "\n)"
19 printpar()
20 subdocp = false
21 next
22}
23
24/\\$/ {
25 getline nl
26 sub(/\\$/,"")
27 $0 = $0 " " nl
28}
29
30/^\.\.\./ {
31 printpar()
32 docp = !docp
33 docend = $2 ? $2 : dend
34 if (docp)
35 print "shellexpand<<" docend
36 else
37 print docend "\n"
38 next
39}
40
41/^\.\./ && docp {
42 subdocp = true
43 end[++endn] = (match($0,"<<") ? substr($0,RSTART+RLENGTH) : "..")
44 command = substr($0, 3, RSTART ? RSTART - 2 : length)
45 $0 = "$$(" (command ? command : "cat") "<<" end[endn]
46}
47
48/^\./ && docp {
49 specialp = 2
50 gsub(/"/,"\\\\&")
51 ln = "$$(" substr($1, 2)
52 for (f=2;f<=NF;f++)
53 ln = ln " \"" $f "\""
54 ln = ln ")"
55 $0 = ln
56}
57
58/^$/ {
59 if (!par) next
60 printpar()
61}
62
63{ par = par (par?"\n":"") $0 }
64{ if (--specialp < 0) specialp = 0 }
65
66END {
67 if (par) printpar()
68 if (docp) print docend
69}
70
71function printpar() {
72 specialp = specialp || (match(par, /^[ ]*</))
73 if (docp) {
74 if (!subdocp && !specialp)
75 par = "<p>" par "</p>"
76 print par | shellfix
77 print ""
78 close(shellfix)
79 } else
80 print par
81 par = ""
82}
diff --git a/etlib.sh b/etlib.sh new file mode 100644 index 0000000..971b879 --- /dev/null +++ b/etlib.sh
@@ -0,0 +1,34 @@
1# etlib
2
3echo()(printf '%s\n' "$*")
4
5attr(){ # attr [NAME|VALUE] ATTR_STRING
6 case "$1" in
7 (name) echo "${2%%=*}" ;;
8 (value) echo "${2#*=}" ;;
9 esac
10}
11
12html_el(){ # el TAG [ATTRS...] [TEXT...] [< INPUT]
13 tag="$1"; attrs= ; text=
14 shift
15 for arg
16 do
17 case "$arg" in
18 (*=*) attrs="$attrs ${arg%%=*}=\"${arg#*=}\""; shift ;;
19 (*) break ;;
20 esac
21 done
22
23 printf '<%s%s>%s' "$tag" "$attrs"
24 test -n "$1" && printf '%s' "$*"
25 if read -r fl
26 then echo "$fl"; cat
27 else echo
28 fi |sed '$s,$,</'"$tag"'>,'
29}
30
31alias p='html_el p'
32alias h1='html_el h1'
33alias blockquote='html_el blockquote'
34alias bq=blockquote
diff --git a/test.et b/test.et new file mode 100644 index 0000000..d62a243 --- /dev/null +++ b/test.et
@@ -0,0 +1,31 @@
1. ./etlib.sh
2alias verse=cat
3...
4here's a test file
5
6.h1 it has "headers" or whatever
7
8..blockquote title=foo
9it has paragraphs of quotes
10..
11
12$$(echo it has shell $scripty-stuff)
13
14..
15escaped par!
16omg wow
17..
18
19..p
20another one :O
21
22holy crap
23this is great
24..
25
26i should have more paragraphs
27
28they are wonderful
29i love them
30
31very much