# # gmi2html.awk -- AWK script to convert a file from text/gemini to text/html # # Copyright (c) 2021 Rodrigo S. Canibano (dracometallium) # Copyright (c) 2021 Jeremy Potter (jwinnie) # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # usage: # $ awk -f gmi2html.awk \ # -v title=
"
next
}
# Detect end of code block
/^```/ && (pre == 1) {
pre = 0
printf "
"
next
}
# Output verbatim text inside of code block
(pre == 1) {
print $0
next
}
# Detect list item
/\* / {
# Detect if this is the first item in
# the list. If so, start a new %s", $0 next } # Detect link /^=>/ { sub(/^=>[ \t]*/, "") url = $0 sub(/[ \t].*$/, "", url) text = $0 sub(url, "", text) sub(/[ \t]*$/, "", text) sub(/^[ \t]*/, "", text) # If linking to a Gemini page, change the extension from # .gmi to .html if ((url !~ /^[a-zA-Z]*:\/\//) && ((url ~ /\.gmi$/) || (url ~ /\.gemini$/))) { sub(/\.gmi$/, ".html", url) sub(/\.gemini$/, ".html", url) } # Show URL if no link text is provided if (text == "") { text = url } printf "", url, text next } # For everything else, just use a
element { printf "
%s
", $0 } # End HTML document END { # End all the remaining lists if (list == 1) { printf "