# # 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= \ # -v css=<css> \ # -v original=<original> < path/to/gmi > path/to/html # # parameters: # <title>: the title of the document, used in the HTML <title> # <css>: relative path to a CSS stylesheet # <original>: URL of the original Gemini document, linked in the footer # Begin HTML document BEGIN { printf "\ <!DOCTYPE html>\ <head>\ <meta charset=\"utf-8\">\ <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\ <link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\ <title>%s\ \ ", css, title pre = 0 list = 0 } # Escape left and right angle brackets { gsub(//, "\\>") } # Detect beginning of code block /^```/ && (pre == 0) { pre = 1 printf "
"
    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 " } # Add a footer pointing back to the original Gemini site, # and advertising Gemini as a better protocol printf "\
\ \ \ ", original }