From 4bfb423a77c35a08f018fafa1b7f2363f0a15c3a Mon Sep 17 00:00:00 2001 From: jwinnie Date: Mon, 29 Nov 2021 15:42:19 -0800 Subject: Initial commit --- gmi2html.awk | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100755 gmi2html.awk diff --git a/gmi2html.awk b/gmi2html.awk new file mode 100755 index 0000000..91f863c --- /dev/null +++ b/gmi2html.awk @@ -0,0 +1,168 @@ +# gmi2html.awk +# +# Copyright (c) 2021 Rodrigo S. Caņibano (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 -- $1 $2 $3 < path/to/gmi > path/to/html +# +# Where: +# - $1 is the title of the site, used in +# - $2 is the path of the stylesheet, relative to the HTML document +# - $3 is the URL of the original Gemini site (it is linked to in the +# footer of the HTML site) +# + +# 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\ + \ + ", ARGV[2], ARGV[1] + 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 "
\ + \ + \ + ", ARGV[3] +} -- cgit 1.4.1-2-gfad0