#!/usr/bin/awk -f # Read gemtext and output strict xhtml # v19 # each blank line after a blank line is an empty
# extra : convert --- tofoo
# * removed ''code''
# * removed linklogos in
# * added anchors to headers
# * do everything in memory to allow top-printing toc
# * fix possible duplicate id
# * fix bug for closing . # * simpler link extension detection # * removed toc # # # options: # -v anchors=0 # set to 1 to enable # # display anchor links in headers, # with class "anchor" (for css) function htmlescape(s) { gsub(/&/,"\\&",s) gsub(/,"\\<",s) gsub(/>/,"\\>",s) gsub(/"/,"\\"",s) gsub(/'/,"\\'",s) return s } function trim(s) { sub(/^[[:blank:]]+/, "", s) sub(/[[:blank:]]+$/, "", s) return s } # commented line with // /^\/\/[:blank:]?/ { # remove leading spaces comment = substr($0, length($1)+2) printf("\n", comment); next } # non empty line /.+/ { blank = 0 } # anything that is not a list /^[^\*]/ { if (ul == 1) { ul = 0 print "
" } pre = (pre + 1) % 2 # toggle pre next } pre { print htmlescape($0) next } # empty line /^$/ { if (blank) { print "" } blank = 1 next } /^\*/ { if (ul == 0) { ul = 1; print "
\n",\ htmlescape(trim($0))) next } # horizontal rule /^---/ { print "%s
%s
\n", htmlescape($0)) } END { if (ul == 1) { print "