#!/usr/bin/gawk -f BEGIN{ # Printing header! print "\n\ \n\ \n\ \n\ \n\ \n\ " # Control variables pre = 0 list = 0 } # First we change all &, < and > into &, < and >. This will cause conflicts # with links (=>) and quotes (>) but it will be easier to check only then than # keep converting at each rule. { gsub(/&/, "\\&") gsub(//, "\\>") } /^```/&&(pre == 0){ # We must close the list! if(list == 1){ list = 0 print "" } pre = 1 printf "
"
    next
}

/^```/&&(pre == 1){
    pre = 0
    print "
" next } (pre == 1){ print $0 next } /\* /{ if(list == 0){ list = 1 print "" } /^---[-]*[ \t]*$/{ print "
" next } /^[ \t]*$/{ print "
" next } /^###/{ sub(/^#[#]*[ \t]*/, "") print "

"$0"

" next } /^##/{ sub(/^#[#]*[ \t]*/, "") print "

"$0"

" next } /^#/{ sub(/^#[#]*[ \t]*/, "") print "

"$0"

" next } /^>/{ sub(/^>[ \t]*/, "") print "

> "$0"

" next } /^=>/{ sub(/^=>[ \t]*/, "") url=$0 sub(/[ \t].*$/, "", url) text=$0 sub(/^[^ \t]*/, "", text) sub(/^[ \t]*/, "", text) sub(/[ \t]*$/, "", text) # If it's a local gemini file, link to the html: if((url !~ /^[a-zA-Z]*:\/\//) && ((url ~ /\.gmi$/) || (url ~ /\.gemini$/))){ sub(/\.gmi$/, ".html", url) sub(/\.gemini$/, ".html", url) } if(text == ""){ text = url } print "

"text"

" next } { print "

"$0"

" } END{ # Closes open list if(list == 1){ print "" } print "\n" }