function strip_markdown(s) { gsub(/<[^>]+>/, "", s) gsub(/[*_`~]/, "", s) gsub(/[\[\]]/, "", s) gsub(/\([^\)]*\)/, "", s) gsub(/^[[:space:]]+|[[:space:]]+$/, "", s) gsub(/[[:space:]]+/, "-", s) return s } function print_header(line) { if (line ~ /^# /) { sub(/^# /, "", line); print "

" line "

" } else if (line ~ /^## /) { sub(/^## /, "", line); print "

" line "

" } else if (line ~ /^### /) { sub(/^### /, "", line); print "

" line "

" } else if (line ~ /^#### /) { sub(/^#### /, "", line); print "

" line "

" } else if (line ~ /^##### /) { sub(/^##### /, "", line); print "
" line "
" } else if (line ~ /^###### /) { sub(/^###### /, "", line); print "
" line "
" } else { print line } } BEGIN { has_prev = 0 in_pre = 0 } { if ($0 ~ /^
/) {
        in_pre = 1
        if (has_prev && prev != "") { print_header(prev); has_prev = 0 }
        print
        next
    }
    if (in_pre) {
        if ($0 ~ /<\/code><\/pre>/) in_pre = 0
        print
        next
    }

    if ($0 ~ /^=+$/) {
        if (has_prev && prev != "" && prev !~ /^<[a-z]/) {
            print "

" prev "

" has_prev = 0 } else { if (has_prev) print_header(prev) print $0 has_prev = 0 } } else if ($0 ~ /^-+$/) { if (has_prev && prev != "" && prev !~ /^<[a-z]/) { print "

" prev "

" has_prev = 0 } else { if (has_prev) print_header(prev) if (length($0) >= 3) print "
" else print $0 has_prev = 0 } } else if ($0 ~ /^[*_]+$/ && length($0) >= 3) { if (has_prev) print_header(prev) print "
" has_prev = 0 } else { if (has_prev) { print_header(prev) } prev = $0 has_prev = 1 } } END { if (has_prev) { print_header(prev) } }