#!/usr/bin/awk -f # HAT TRICK # (C) 2022 C. Duckworth # ht.awk converts mostly-html (with some conveniences) to actual html function bufpush(s) { BUF = BUF (BUF ? "\n" : "") s; } function buflush() { if (BUF) print BUF; BUF = ""; if (tag && (tag != "html") && (tag != "raw")) print "" tag ">"; } function esc(t) { # This is of much more limited utility than I initially realized. gsub(/&/, "\\&", t); gsub(/, "\\<", t); gsub(/>/, "\\>", t); sub(/^ /, "\\ ", t); return t; } /^;/ { sub(/^;/,""); print ""; next; } /^ { # Raw HTML if (! (tag == "html")) tag = "html"; bufpush($0); next; } /^```$/ { # Raw block if (! (tag == "raw")) { tag = "raw"; getline; bufpush("
" $0);
} else {
bufpush("
");
buflush();
tag = "";
}
next;
}
/^=>/ { # Links (Gemini-style)
if (tag == "raw") next;
link = "" $3;
for (i=4;i<=NF;i++) link = link " " $i;
link = link "";
bufpush(link);
next;
}
/^-/ { # Unordered lists
if (tag == "raw") next;
if (! (tag == "ul")) tag = "ul";
sub(/^-[ \t]*/, "