[ANN] html2gemini and html2gmi-cli - A Go library and app for converting HTML to Gemini

Luke Emmet luke at marmaladefoo.com
Fri Jul 31 18:54:09 BST 2020



On 31-Jul-2020 14:34, Matthew Graybosch wrote:
> Aside from all of the other stuff I want to do, I've been curious about
> learning Go for a while. I'm tempted to take your code and see if I can
> turn it around to generate HTML from gemini text.
>
> There's no reason I shouldn't be able to do it; the existence of
> portal.mozz.us proves that converting text/gemini to text/html is
> possible. It's just a matter of implementing the function as a tool I
> could use in a makefile.
Hello Matthew

Gemini is a couple of orders of magnitude simpler than HTML, so you 
don't need to start from such a complex base as looking at an HTML 
parser and sanitiser. It is *much* simpler to go from Gemini to HTML.

Here is a very simple pseudocode for a gemini to html converter, you can 
tart it up as you wish:

for each line in lines
if the line starts with heading marker (#, ##, ###), output: <h1> 
{{line}} </h1> (for #, use h2 and h3 accordingly)
if the line starts with bullet marker (*) , output: <div> • {{line}}</div>
if the line starts with link marker, split the line and output: <div><a 
href="{{target}}">{{display}}</a></div>
if the line starts ```, toggle a flag and output <pre> if the flag is 
now on, or </pre> if the flag is off
otherwise output: <div>{{line}}</div> unless the line is empty, 
otherwise <div> </div>
next

You'll need to escape the content (e.g. &, <,> etc)

You can play around with CSS styling if you want to make it look pretty.

voila!

Best Wishes

- Luke

P.S. I have a more detailed version of a gemini to html converter here, 
used within GemiNaut, it might be of interest to look at. But its not in 
Go, but Rebol:

https://github.com/LukeEmmet/GemiNaut/blob/master/GemiNaut/GmiConverters/GmiToHtml.r3


More information about the Gemini mailing list