summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorjwinnie <jwinnie@tilde.institute>2021-11-29 16:16:23 -0800
committerjwinnie <jwinnie@tilde.institute>2021-11-29 16:16:23 -0800
commit29606788f53b4e8831d3f812cc379bee804a14d2 (patch)
treeabcc1d6f72dc164054d7c074743e6231d1569e73
parent4bfb423a77c35a08f018fafa1b7f2363f0a15c3a (diff)
downloadgmi2html-29606788f53b4e8831d3f812cc379bee804a14d2.tar.gz
Improve documentation and formatting
-rwxr-xr-xgmi2html.awk68
1 files changed, 37 insertions, 31 deletions
diff --git a/gmi2html.awk b/gmi2html.awk
index 91f863c..42334ac 100755
--- a/gmi2html.awk
+++ b/gmi2html.awk
@@ -1,6 +1,6 @@
 # gmi2html.awk
 #
-# Copyright (c) 2021 Rodrigo S. Caņibano (dracometallium)
+# 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
@@ -16,27 +16,27 @@
 # 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 <title>
-# 	- $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)
+# usage:
+#   $ awk -f gmi2html.awk -- <title> <css> <url> < 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
+#   <url>: 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</title>\
-              </head>\
-              <body>", ARGV[2], ARGV[1]
-    pre = 0
+    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</title>\
+</head>\
+<body>", ARGV[2], ARGV[1]
+
+    pre  = 0
     list = 0
 }
 
@@ -70,12 +70,13 @@ BEGIN {
 /\* / {
     # Detect if this is the first item in
     # the list. If so, start a new <ul>.
-    if(list == 0){
+    if (list == 0) {
         list = 1
         printf "<ul>"
     }
 
     sub(/\* [ \t]*/, "")
+
     printf "<li>%s</li>", $0
     next
 }
@@ -89,6 +90,7 @@ BEGIN {
 # Detect heading 3
 /^###/ {
     sub(/^#[#]*[ \t]*/, "")
+
     printf "<h3>%s</h3>", $0
     next
 }
@@ -96,6 +98,7 @@ BEGIN {
 # Detect heading 2
 /^##/ {
     sub(/^#[#]*[ \t]*/, "")
+
     printf "<h2>%s</h2>", $0
     next
 }
@@ -103,6 +106,7 @@ BEGIN {
 # Detect heading 1
 /^#/ {
     sub(/^#[#]*[ \t]*/, "")
+
     printf "<h1>%s</h1>", $0
     next
 }
@@ -110,6 +114,7 @@ BEGIN {
 # Detect blockquote
 /^&gt;/ {
     sub(/^&gt;[ \t]*/, "")
+
     printf "<blockquote><p>&ldquo;%s&rdquo;</p></blockquote>", $0
     next
 }
@@ -118,10 +123,10 @@ BEGIN {
 /^=&gt;/ {
     sub(/^=&gt;[ \t]*/, "")
 
-    url=$0
+    url = $0
     sub(/[ \t].*$/, "", url)
 
-    text=$0
+    text = $0
     sub(url, "", text)
     sub(/[ \t]*$/, "", text)
     sub(/^[ \t]*/, "", text)
@@ -138,7 +143,7 @@ BEGIN {
         text = url
     }
 
-    printf "<p><code>=&gt;</code> <a href=\""url"\">%s</a></p>", text
+    printf "<p><code>=&gt;</code> <a href=\"%s\">%s</a></p>", url, text
     next
 }
 
@@ -156,13 +161,14 @@ END {
 
     # Add a footer pointing back to the original Gemini site,
     # and advertising Gemini as a better protocol
-    printf "<hr>\
-            <footer>\
-              <small>\
-                Also available on <a href=\"gemini://%s\">Gemini</a>\
-                &mdash; a simpler, more secure World Wide Web.\
-              </small>\
-            </footer>\
-          </body>\
-        </html>", ARGV[3]
+    printf "\
+<hr>\
+<footer>\
+<small>\
+Also available on <a href=\"gemini://%s\">Gemini</a>\
+&mdash; a simpler, more secure World Wide Web.\
+</small>\
+</footer>\
+</body>\
+</html>", ARGV[3]
 }