💾 Archived View for gemini.thegonz.net › glog › 200919-gmi2html.gmi captured on 2024-06-16 at 12:35:03. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2020-09-24)

-=-=-=-=-=-=-

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.