#!/usr/bin/awk -f BEGIN{ # Printing header! if(ENVIRON["baseURL"] == ""){ baseURL="/" } else { baseURL = ENVIRON["baseURL"] } if(ENVIRON["webLang"] == ""){ webLang="en" } else { webLang = ENVIRON["webLang"] } printf("\n\ \n\ \n\ \n\ ^_^\n\ \n\ \n\ \n", webLang, webLang, baseURL) # Link types lImg = "^pic:" # 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 "" } emptyLine = 0 pre = 1 printf "
"
    next
}

/^```/&&(pre == 1){
    pre = 0
    print "
" next } (pre == 1){ print $0 next } # We insert empty lines only if there is more than one. We don't need to add # extra spacing between paragraphs. /^[ \t]*$/&&(emptyLine == 0){ emptyLine = 1 next } /^[ \t]*$/&&(emptyLine == 1){ print "
" next } # If there is something that is not an empty line (emptyLine == 1){ emptyLine = 0 } /\* /{ if(list == 0){ list = 1 print "" } /^---/{ 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 } if(text ~ lImg){ sub(lImg,"",text) sub(/^[ \t]*/,"",text) print "

"text"

" } else { print "

⇒ "text"

" } next } { print "

"$0"

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