💾 Archived View for gemi.dev › gemini-mailing-list › 000316.gmi captured on 2024-05-26 at 15:42:30. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-12-28)

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

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

1. Luke Emmet (luke (a) marmaladefoo.com)

Hi Everyone

2 Gemini software announcements here, but they are related.

You can use them as-is, for example for file conversion or dual 
web/gemini publishing.

Or if you are consuming HTML from the internet, you might want to 
simplify the HTML first using Readability or other HTML simplifying 
libraries to remove extraneous navigational cruft.

Bug fixes and improvement suggestions welcomed.

Best Wishes

  - Luke

__________

# html2gemini - A Go library to convert HTML to text/gemini

I've forked and adapted an existing Go library html2text which outputs a 
flavour of markdown so that it instead outputs text/gemini. Main features:

- heading levels, bullets, blockquote, preformatted content
- links done using embedded numeric citations and gemini links
- tables prettified and wrapped in preformatted text

   https://github.com/LukeEmmet/html2gemini

__________

# html2gmi-cli - A command line app to convert HTML to text/gemini files

A simple command line application wrapping the html2gemini library you 
can put into your command line workflows.

   https://github.com/LukeEmmet/html2gmi-cli

Link to individual message.

2. Matthew Graybosch (hello (a) matthewgraybosch.com)

On Fri, 31 Jul 2020 12:03:53 +0100
Luke Emmet <luke at marmaladefoo.com> wrote:

> Hi Everyone
> 
> 2 Gemini software announcements here, but they are related.

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.

(mostly thinking out loud. sorry.)

-- 
Matthew Graybosch		https://matthewgraybosch.com
#include <disclaimer.h>	gemini://starbreaker.org
	 			gemini://tanelorn.city
"Out of order?! Even in the future nothing works."

Link to individual message.

3. Luke Emmet (luke (a) marmaladefoo.com)



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>&nbsp;</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

Link to individual message.

4. Luke Emmet (luke (a) marmaladefoo.com)

I've renamed the command line app to html2gmi, so the correct links are now:

Go library:

https://github.com/LukeEmmet/html2gemini

Command line app:

https://github.com/LukeEmmet/html2gmi

Best Wishes

- Luke

Link to individual message.

---

Previous Thread: [ANN] New Gemini Site

Next Thread: Proxying