{ prev = this; }
{ if (prev == "pre-on" || prev == "pre") this = "pre"; }
{ if (this != "pre") this = "text" ; }
/^```/ { if (this != "pre") this = "pre-on" ;
else this = "pre-off"; }
/^#/ { if (this != "pre") this = "h1" ; }
/^##/ { if (this != "pre") this = "h2" ; }
/^###/ { if (this != "pre") this = "h3" ; }
/^* / { if (this != "pre") this = "list" ; }
/^>/ { if (this != "pre") this = "quote" ; }
function closeln() {
if (prev == "text") printf("</pre>");
if (prev == "pre-off") printf("</pre>");
if (prev == "list") printf("</ul>");
if (prev == "quote") printf("</pre></blockquote>");
}
prev != this { closeln(); }
prev { printf("\n"); }
END { closeln(); printf("\n"); }
prev != this {
if (this == "text") printf("<pre class=text>");
if (this == "pre-on") printf("<pre class=code>");
if (this == "list") printf("<ul>");
if (this == "quote") printf("<blockquote><pre class=text>");
}
function makesafe(s) {
gsub(/&/, "\\&", s);
gsub(/</, "\\<", s);
gsub(/>/, "\\>", s);
gsub(/"/, "\\"", s);
gsub(/'/, "\\'", s);
return s;
}
function skipws() {
return makesafe(substr($0, index($0, $1)));
}
this == "text" && /^=>/ {
sub(/^=>/, "");
url = makesafe($1);
printf("<a href=\"%s\">", url);
$0 = substr($0, index($0, $1) + length($1));
printf("%s</a>", ($NF) ? skipws() : url);
next;
}
this == "text" { printf("%s", makesafe($0)); }
this == "pre" { printf("%s", makesafe($0)); }
this == "h1" { sub(/^#/, "") ; printf("%s", skipws()); }
this == "h2" { sub(/^##/, "") ; printf("%s", skipws()); }
this == "h3" { sub(/^###/, ""); printf("%s", skipws()); }
this == "list" { sub(/^* /, ""); printf("%s", skipws()); }
this == "quote" { sub(/^>/, "") ; printf("%s", skipws()); }
text/plain
This content has been proxied by September (ba2dc).