#!/usr/bin/awk -f # Read gemtext and output html5 # v23 # each blank line after a blank line is an empty
# extra : convert --- to
# extra : lines starting with // are comments # # CHANGELOG: # * add logo according to hyperlink protocol # logo in # * extra : lines starting with // are comments # * removed   since it is not xml # * changed default for linklogo : disabled # ''foo'' -> foo # * 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 \n"; curlvl-- } print "" # close toc } # 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 printf("\n"); } } # code block /^```/ { if (pre) { printf("\n") } else { printf("
") }
	pre = (pre + 1) % 2 # toggle pre
	next
}

pre {
	printf("%s\n", htmlescape($0))
	next
}


# empty line
/^$/ {
	if (blank) { printf("
\n") } blank = 1 next } /^\*/ { if (ul == 0) { ul = 1; printf("\n") } if (tocn > toc) { toctoc() } }