diff options
-rwxr-xr-x | et | 32 | ||||
-rw-r--r-- | template.htm | 3 | ||||
-rw-r--r-- | test.et | 1 | ||||
-rwxr-xr-x | tet | 9 |
4 files changed, 35 insertions, 10 deletions
diff --git a/et b/et index 144b10a..19a8833 100755 --- a/et +++ b/et | |||
@@ -3,24 +3,31 @@ | |||
3 | # usage: et <file> | sh | 3 | # usage: et <file> | sh |
4 | 4 | ||
5 | BEGIN { | 5 | BEGIN { |
6 | dend = ";doc_end;" | 6 | # Tuneables |
7 | postproc = postproc ? postproc : "shexpand" | ||
8 | bodyfunc = bodyfunc ? bodyfunc : "body" | ||
9 | # Globals | ||
10 | wrpfx = ";:"; shxpfx = "!shx!"; def_docend = "---end---" | ||
11 | pretext = bodyfunc"(){\n"; posttext = "}\n"bodyfunc | ||
7 | # Ask sed to do these b/c awk has no capture groups ;_; | 12 | # Ask sed to do these b/c awk has no capture groups ;_; |
8 | shellfix = "sed -E" \ | 13 | shellfix = "sed -E" \ |
9 | " -e 's/`/\\\\`/g'" \ | 14 | " -e 's/`/\\\\`/g'" \ |
10 | " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \ | 15 | " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \ |
11 | " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'" | 16 | " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'" |
12 | shxwrap = " -e 's/^/:/'" | 17 | shxwrap = " -e 's/^/"wrpfx"/'" |
13 | htmlfix = "sed -E" \ | 18 | htmlfix = "sed -E" \ |
14 | " -e 's#([^\\\\]|^)&#\\1\\&#g'" \ | 19 | " -e 's#([^\\\\]|^)&#\\1\\&#g'" \ |
15 | " -e 's#([^\\\\]|^)<#\\1\\<#g'" \ | 20 | " -e 's#([^\\\\]|^)<#\\1\\<#g'" \ |
16 | " -e 's#([^\\\\]|^)>#\\1\\>#g'" \ | 21 | " -e 's#([^\\\\]|^)>#\\1\\>#g'" \ |
17 | " -e 's#\\\\([&<>])#\\1#g'" | 22 | " -e 's#\\\\([&<>])#\\1#g'" |
18 | true = 1 ; false = 0 | 23 | true = 1 ; false = 0 |
19 | print "#!/bin/sh\n########## generated with excitable text #########" | 24 | print "### excitable text ###" |
20 | print "shexpand()(eval \"$(:;(echo 'cat<<.';cat|sed 's/^/,/';echo .)"\ | 25 | print "wrap()(sed \"s/^/$1/\");unwrap()(sed \"s/^$1//\")" |
21 | "|unwrap ,)\")" | 26 | print "shexpand()(eval"\ |
27 | " \"$(:;(echo 'cat<<.';sed 's/^/"shxpfx"/';echo .)"\ | ||
28 | "|unwrap "shxpfx")\")" | ||
22 | print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")" | 29 | print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")" |
23 | print "wrap()(sed \"s/^/$1/\")\nunwrap()(sed \"s/^$1//\")" | 30 | print "postproc=" postproc |
24 | } | 31 | } |
25 | 32 | ||
26 | end[endn] && $0 == end[endn] { | 33 | end[endn] && $0 == end[endn] { |
@@ -39,9 +46,10 @@ end[endn] && $0 == end[endn] { | |||
39 | /^\.\.\./ { | 46 | /^\.\.\./ { |
40 | printpar() | 47 | printpar() |
41 | docp = !docp | 48 | docp = !docp |
42 | docend = $2 ? $2 : dend | 49 | docend = $2 ? $2 : def_docend |
43 | if (docp) print "unwrap :<<'" docend "'|shexpand" | 50 | if (docp) print pretext "unwrap '" wrpfx "'" \ |
44 | else print docend "\n" | 51 | "<<'" docend "'|$postproc" |
52 | else end_text() | ||
45 | next | 53 | next |
46 | } | 54 | } |
47 | 55 | ||
@@ -71,7 +79,11 @@ end[endn] && $0 == end[endn] { | |||
71 | 79 | ||
72 | END { | 80 | END { |
73 | if (par) printpar() | 81 | if (par) printpar() |
74 | if (docp) print docend | 82 | if (docp) end_text() |
83 | } | ||
84 | |||
85 | function end_text() { | ||
86 | print docend "\n" posttext | ||
75 | } | 87 | } |
76 | 88 | ||
77 | function printpar() { | 89 | function printpar() { |
diff --git a/template.htm b/template.htm new file mode 100644 index 0000000..13d48d5 --- /dev/null +++ b/template.htm | |||
@@ -0,0 +1,3 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <title>${title}</title> | ||
3 | <body>$(body)</body> | ||
diff --git a/test.et b/test.et index 927a4af..60c59bc 100644 --- a/test.et +++ b/test.et | |||
@@ -1,5 +1,6 @@ | |||
1 | . ./etlib.sh | 1 | . ./etlib.sh |
2 | alias verse=cat | 2 | alias verse=cat |
3 | title="test file" | ||
3 | ... | 4 | ... |
4 | here's a test file | 5 | here's a test file |
5 | .a href="https://example.com" a link or something!! | 6 | .a href="https://example.com" a link or something!! |
diff --git a/tet b/tet new file mode 100755 index 0000000..c97d677 --- /dev/null +++ b/tet | |||
@@ -0,0 +1,9 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | __template__="$1"; shift | ||
4 | et="$(which et||echo ./et)" | ||
5 | |||
6 | "$et" "$@" | sed '$d' | ||
7 | echo 'shexpand<<%' | ||
8 | cat "$__template__" | ||
9 | echo % | ||