# Status: # [.] Inline HTML # [x] Autoescape # [ ] Block elements # [x] Paragraph # [x] Line break # [.] Headers (atx and setex) # [x] Blockquotes # [ ] Lists # [ ] Code blocks # [x] Horizontal rules # [ ] Span elements # [ ] Links # [x] Emphasis # [ ] Code # [ ] Images # [ ] Other # [ ] Autolinks # [ ] Escapes # # [ ] Non-standard features # [ ] Strikethrough ~~...~~ # [ ] Superscript ^^...^^ # [ ] Subscript ~...~ # [ ] Footnote [^...] (with user customizations) # [ ] Task list - [ ] # [ ] Definition lists # [ ] Fenced code blocks ```lang ``` # [ ] Table alignment BEGIN { prev_blankline = blankline = 1 newStack("bq-level") } { prev_blankline = blankline blankline = 1 } /[^[:blank:]]/ { blankline = 0 } # Blockquote Part 1/2 /^>[[:blank:]]*$/ { next } /^> / { level = 0 while (match($0, /^> [[:blank:]]*/)) { $0 = substr($0, RLENGTH + 1) level += RSTART while (topStack("bq-level") > level) { print "" popStack("bq-level") } if (topStack("bq-level") < level) { print "
" pushStack("bq-level", level) } } } # Inline HTML /^[[:blank:]]*<\/?[[:alnum:]]+/ { print next } # Horizontal rules /^(-|\*|_) ?(-|\*|_) ?(-|\*|_|[[:blank:]])+$/ { print "
" blankline = 1 next } # Line break / $/ { sub(/ $/, "
") } # atx-style headers /^[[:blank:]]*#+/ { match($0, /#+/) if (RLENGTH <= 6) { gsub(/^[[:blank:]]*#+[[:blank:]]*/, "") gsub(/[[:blank:]]*#+[[:blank:]]*$/, "") print "" $0 "" blankline = 1 next } } # setex-style headers TODO # Code blocks /^( |\t)[[:blank:]]*/ { } # Paragraphs prev_blankline && !blankline && lengthStack("bq-level") == 0 { print "

" } !prev_blankline && blankline && lengthStack("bq-level") == 0 { print "

" } # Blockquote Part 2/2 blankline { while (lengthStack("bq-level") > 0) { print "
" popStack("bq-level") } } # Auto-escape & /&/ { ampstart = 0 while (match(substr($0, ampstart + 1), /&/)) { ampstart += RSTART if (match(substr($0, ampstart), /&[[:alnum:]#]+;/)) { continue } $0 = substr($0, 1, ampstart - 1) "&" substr($0, ampstart + 1) } } # Auto-escape < /") sub(/__/, "") } } /\*\*.+\*\*/ { while (match($0, /\*\*/)) { sub(/\*\*/, "") sub(/\*\*/, "") } } /_[^_].+_/ { while (match($0, /_/)) { sub(/_/, "") sub(/_/, "") } } /\*[^_].+\*/ { while (match($0, /\*/)) { sub(/\*/, "") sub(/\*/, "") } } { print } END { if (!blankline && lengthStack("bq-level") == 0) { print "

" } while (lengthStack("bq-level") > 0) { print "" popStack("bq-level") } }