-- Leo's gemini proxy

-- Connecting to gemini.thegonz.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

gmi2html.sed

I thought it would be an amusing little exercise to write a gmi to html stream converter in pure sed.

/gmi2html.sed

It was kind of amusing. Writing non-trivial sed scripts feels a lot like programming in an esoteric language like Brainfuck or Befunge. On the one hand it has very limited control structures -- you have conditions and goto, but not even a gosub. On the other it has the massively powerful inbuilt substitution command. It's easily Turing complete, but you'd have to be crazy to actually program in it. Which is why it's fun to.

Turing machine in sed


Anyway, thanks to the line-based design of gmi which fits perfectly with classic unix tools like sed, this gmi2html script was straightforward; only tricky parts were handling the necessary state to deal with preformatting toggles and lists, doing html element substitutions without messing up the '>' and '=>' lines, and deciding what to do about the title -- in the end I decided to consider a first line of the form "# foo" to mean the document has title foo, and to give it title "Untitled" otherwise. I also adapted the script for markdown, which is even more straightforward (apart from link lines it's basically a no-op).

/gmi2md.sed


The scripts are released under CC0 -- I believe in copyleft, but not for something this trivial. Do what you will with them.

-- Response ended

-- Page fetched on Thu Mar 28 16:06:19 2024