Files
kewt/awk/paragraphs.awk
N0\A 009877ae76
All checks were successful
Lint / shellcheck (push) Successful in 17s
feat: colour palettes
2026-04-01 14:23:12 +02:00

53 lines
982 B
Awk

BEGIN {
in_p = 0
in_pre = 0
}
{
if ($0 ~ /<pre>/) in_pre = 1
if (in_pre) {
if (in_p) { print "</p>"; in_p = 0 }
print
if ($0 ~ /<\/pre>/) in_pre = 0
next
}
if ($0 ~ /^<\/?(div|table|p|[ou]l|h[1-6]|[bh]r|blockquote|li|hr|section|article|nav|aside|header|footer|dl|dt|dd|script|style|iframe|details|summary|figure|figcaption|audio|video|picture)/) {
if (in_p) {
print "</p>"
in_p = 0
}
print
next
}
if ($0 ~ /^[\t ]*!([a-zA-Z])?\[[^\]]*\](\([^)]*\))?[\t ]*$/ || $0 ~ /^[\t ]*!!?\[[^\]]*\](\([^)]*\))?[\t ]*$/) {
if (in_p) {
print "</p>"
in_p = 0
}
print
next
}
if ($0 == "") {
if (in_p) {
print "</p>"
in_p = 0
}
print
next
}
if (!in_p) {
print "<p>"
in_p = 1
}
print
}
END {
if (in_p) print "</p>"
}