#!/bin/awk -f BEGIN { in_pre = 0; in_list = 0; in_html = 0; html_comment = 0; first_pre = 0; } !html_comment && // { html_comment = 0; print $0; next } html_comment { print $0; next } !in_html && /^\^\^\^/ { in_html = 1; next } in_html && /^\^\^\^/ { in_html = 0; next } in_html { print $0; next } !in_pre && /^```/ { in_pre = 1; first_pre = 1; if (in_list) { in_list = 0; print(""); } printf "
";
next
}
in_pre && /^```/ { in_pre = 0; first_pre = 0; print ""; next }
in_pre && first_pre {print san($0); first_pre = 0; next}
in_pre { print san($0); next }
/^###/ { output("", substr($0, 2), ""); next } /^\*/ { output("
", $0, "
"); next } END { if (in_list) print "" if (in_pre) print "" if (in_html) print "" print "