about summary refs log tree commit diff stats
path: root/ht.awk
diff options
context:
space:
mode:
authorCase Duckworth2022-05-27 13:27:21 -0500
committerCase Duckworth2022-05-27 13:27:21 -0500
commite7254223846dbec352628aa9d156e0fe323a4e93 (patch)
tree8c02009b7981a1182b952ccf307b52f1700bb5b3 /ht.awk
parentUpdate footer -- and properly integrate it into Make (diff)
downloadhat-trick-e7254223846dbec352628aa9d156e0fe323a4e93.tar.gz
hat-trick-e7254223846dbec352628aa9d156e0fe323a4e93.zip
New post, asset moving, dir-locals, etc.
Diffstat (limited to 'ht.awk')
-rwxr-xr-xht.awk24
1 files changed, 23 insertions, 1 deletions
diff --git a/ht.awk b/ht.awk index faa729d..a382ae7 100755 --- a/ht.awk +++ b/ht.awk
@@ -11,7 +11,8 @@ function bufpush(s) {
11function buflush() { 11function buflush() {
12 if (BUF) print BUF; 12 if (BUF) print BUF;
13 BUF = ""; 13 BUF = "";
14 if (tag && (tag != "html")) print "</" tag ">"; 14 if (tag && (tag != "html") && (tag != "raw"))
15 print "</" tag ">";
15} 16}
16 17
17function esc(t) { 18function esc(t) {
@@ -19,6 +20,7 @@ function esc(t) {
19 gsub(/&/, "\\&amp;", t); 20 gsub(/&/, "\\&amp;", t);
20 gsub(/</, "\\&lt;", t); 21 gsub(/</, "\\&lt;", t);
21 gsub(/>/, "\\&gt;", t); 22 gsub(/>/, "\\&gt;", t);
23 sub(/^ /, "\\&nbsp;", t);
22 return t; 24 return t;
23} 25}
24 26
@@ -30,7 +32,21 @@ function esc(t) {
30 next; 32 next;
31} 33}
32 34
35/^```$/ { # Raw block
36 if (! (tag == "raw")) {
37 tag = "raw";
38 getline;
39 bufpush("<pre><code>" $0);
40 } else {
41 bufpush("</code></pre>");
42 buflush();
43 tag = "";
44 }
45 next;
46}
47
33/^=>/ { # Links (Gemini-style) 48/^=>/ { # Links (Gemini-style)
49 if (tag == "raw") next;
34 link = "<a href=\"" esc($2) "\">" $3; 50 link = "<a href=\"" esc($2) "\">" $3;
35 for (i=4;i<=NF;i++) link = link " " $i; 51 for (i=4;i<=NF;i++) link = link " " $i;
36 link = link "</a>"; 52 link = link "</a>";
@@ -39,21 +55,25 @@ function esc(t) {
39} 55}
40 56
41/^-/ { # Unordered lists 57/^-/ { # Unordered lists
58 if (tag == "raw") next;
42 if (! (tag == "ul")) tag = "ul"; 59 if (! (tag == "ul")) tag = "ul";
43 sub(/^-[ \t]*/, "<li>"); 60 sub(/^-[ \t]*/, "<li>");
44} 61}
45 62
46/^[0-9]+\./ { # Ordered lists 63/^[0-9]+\./ { # Ordered lists
64 if (tag == "raw") next;
47 if (! (tag == "ol")) tag = "ol"; 65 if (! (tag == "ol")) tag = "ol";
48 sub(/^[0-9]+\.[ \t]/, "<li>"); 66 sub(/^[0-9]+\.[ \t]/, "<li>");
49} 67}
50 68
51/^>/ { # Blockquotes 69/^>/ { # Blockquotes
70 if (tag == "raw") next;
52 if (! (tag == "blockquote")) tag = "blockquote"; 71 if (! (tag == "blockquote")) tag = "blockquote";
53 sub(/^>[ \t]*/,""); 72 sub(/^>[ \t]*/,"");
54} 73}
55 74
56/^#+/ { # Headers 75/^#+/ { # Headers
76 if (tag == "raw") next;
57 match($0, /^#+/); 77 match($0, /^#+/);
58 if (! (tag == "h" RLENGTH)) { 78 if (! (tag == "h" RLENGTH)) {
59 buflush(); 79 buflush();
@@ -63,6 +83,7 @@ function esc(t) {
63} 83}
64 84
65/^$/ { 85/^$/ {
86 if (tag == "raw") next;
66 buflush(); 87 buflush();
67 tag = ""; 88 tag = "";
68} 89}
@@ -70,6 +91,7 @@ function esc(t) {
70/./ { 91/./ {
71 if (! tag) tag = "p"; 92 if (! tag) tag = "p";
72 if (! BUF) bufpush("<" tag ">"); 93 if (! BUF) bufpush("<" tag ">");
94 if (tag == "raw") $0 = esc($0);
73 bufpush($0); 95 bufpush($0);
74} 96}
75 97