Commit Diff


commit - e5bee1448fa21c545ae3bcd0a6a0adf3c5347fac
commit + 335917eb5ce1c5bbe4e99fdbb4de2278ed58cd4c
blob - /dev/null
blob + 0186c32d46d0315108b257b674d472c2bf394b55 (mode 644)
--- /dev/null
+++ bin/gmi2txt.lp
@@ -0,0 +1,100 @@
+# gmi2txt
+
+gmi2txt is a small script to format a text/gemini page.  needs par(1)
+
+	#!/usr/bin/awk -f
+	
+	BEGIN {
+		in_pre = 0
+	
+		title1 = "sed s/./=/g"
+		title2 = "sed s/./-/g"
+		parl = "par 72p2"
+		pari = "par 72p3 | sed '2,$s/^ \\*/  /'"
+		parq = "par 72p2"
+		par = "par 72"
+	}
+	
+	!in_pre && /^```/ {
+		in_pre = 1
+		print $0
+		next
+	}
+	in_pre && /^```/ {
+		in_pre = 0
+		print $0
+		next
+	}
+	in_pre { print $0; next }
+	
+	// {
+		# print a blank line between links and other line
+		# types, unless there's already a blank line.
+	
+		if (last_was_link && !match($0, "^[ \t]*$")) {
+			print "";
+		}
+	}
+	
+	/^=>/ {
+		last_was_link = 1
+	
+		$0 = gensub("=> *", "", 1)
+		link = $1
+		$1 = ""
+		text = gensub("^ *", "", 1)
+		if (text == "")
+			text = link
+	
+		printf("~ %s\n", text) | parl
+		printf("%s\n", link)
+		close(parl)
+		next
+	}
+	
+	// { last_was_link = 0 }
+	
+	/^###/ {
+		t = gensub("### *", "", "1")
+		printf("-%s-\n", t)
+		next
+	}
+	
+	/^##/ {
+		t = gensub("## *", "", 1)
+		print t
+		print t | title2
+		close(title2)
+		next
+	}
+	
+	/^#/ {
+		t = gensub("# *", "", 1)
+		print t
+		print t | title1
+		close(title1)
+		next
+	}
+	
+	/^>/ {
+		print $0 | parq
+		close(parq)
+		next
+	}
+	
+	/^\*/ {
+		printf(" %s", $0) | pari
+		close(pari)
+		next
+	}
+	
+	// {
+		print $0 | par
+		close(par)
+	}
+	
+	END {
+		if (in_pre)
+			print "```"
+	}
+	
blob - 10e394d16be9a6170dba74cde7ac6364efa27b06
blob + 7be3f366f8585a6bfd94549beee0cd96044ebf86
--- gen
+++ gen
@@ -68,6 +68,7 @@ pair bin/amused-monitor	bin/amused-monitor.lp +x
 pair bin/browser	bin/browser.lp	+x
 pair bin/clip		bin/clip.lp	+x
 pair bin/sshot		bin/sshot.lp	+x
+pair bin/gmi2txt	bin/gmi2txt.lp	+x
 
 pair .config/herbstluftwm/autostart	config/herbstluftwm/autostart.lp
 pair .config/herbstluftwm/panel		config/herbstluftwm/panel.lp	+x