💾 Archived View for tilde.club › ~oldernow › 2023-11-28-11-27-38.gmi captured on 2023-12-28 at 17:17:32. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
Yesterday (due to reading some thread that included the author of 'cURL' weighing in on the Gemini protocol, and some of the discussion having me starting to feel as though the absence of inline links *was* rather silly...) I messed with a couple Lua scripts tentatively called 'gemtext2gemtext' and 'gemtext2html' to transform what I'm tentatively calling "pre-gemtext" to gemtext and html, respectively.
"pre-gemtext" for now addresses the subset of full gemtext that I regularly use, namely (apologies if I botch the actual gemtext element terminology):
"gemtext2gemtext" is pretty trivial, as the only thing different between it and gemtext is it permits specification of inline links
"gemtext2html" leads to the html tags people familiar with them might expect.
Given we're talking software, of course there had to be one hellish (relative to most of the task) aspect, namely converting the inline links specification into what gemtext truly demands, i.e. the link specifications on lines separate from surrounding paragraph material.
Of course, maybe I just suck. But this was easily handled in the gemtext2html case via Lua's "string.gsub()", which effortlessly transforms all [URL|"TITLE"] (the syntax I chose) to <a href="URL">TITLE</a>.
Using string.gsub in gemtext2gemtext works similarly, although of course one must prepend and append newlines to the resulting transformation so the link spec is on its own line. *BUT*, while that works great for [URL|"TITLE"] specs truly within surrounding text, when such a spec occurs at the very end of a line, the result is too many newlines on the end, meaning too many consecutive empty lines in the resulting gemtext.
I could not find a solution for that using just string.gsub(). All I could think was to stage the resulting gemtext in a table, then cycle through the table to reduce cases of consecutive empty lines to a single empty line before outputting. But I start feeling silly resorting to what I have to believe is unncessary caching in order to "look ahead"... I want to be able to process in a "read lines from a file" loop. But I'm just plain not algorithmically astute enough (or whatever it is..) so see through/around this challenge.
Always f'ing something....