#!/bin/sed -Ef

gmi2html: Sed script to convert text/gemini to html.

Based on v0.14.2 of the gemini spec.

#

This script is dedicated to the public domain according to the terms of CC0:

https://creativecommons.org/publicdomain/zero/1.0/

TODO: add meta charset header, I suppose, to ensure utf8?

s/\&/\&/g

s/"/\"/g

s/

/^=?>/! s/>/\>/g

/^=?>/ {

:loop

s/^((=?>).*)>/\1\>/

t loop

}

1 {

i\

\

h

s/^#\s*//

t title_set

s/.*/Untitled/

:title_set

s/.*/&<\/title><\/head>/</p><p>p</p><p>i\</p><p><body></p><p>s/.*//</p><p>x</p><p>}</p><p>x</p><p>/^```/ {</p><p>x</p><p>/^```/ {</p><p>s/.*/<\/pre>/</p><p>h</p><p>}</p><p>b end</p><p>}</p><p>/^(\*|=>) / {</p><p>x</p><p>/^(\*|=>) / {</p><p>s/^\* (.*)/<li>\1<\/li>/</p><p>s/^=>\s*([^[:space:]]+)\s*$/<li><a href="\1">\1<\/a><\/li>/</p><p>s/^=>\s*([^[:space:]]+)\s+(.+)/<li><a href="\1">\2<\/a><\/li>/</p><p>b end</p><p>}</p><p>i\</p><p></ul></p><p>h</p><p>}</p><p>g</p><p>t linetypes</p><p>:linetypes</p><p>s/^```.*/<pre>/</p><p>s/^\* (.*)/<ul><li>\1<\/li>/</p><p>s/^=>\s*([^[:space:]]+)\s*$/<ul><li><a href="\1">\1<\/a><\/li>/</p><p>s/^=>\s*([^[:space:]]+)\s+(.+)/<ul><li><a href="\1">\2<\/a><\/li>/</p><p>s/^###\s*(.*)/<h3>\1<\/h3>/</p><p>s/^##\s*(.*)/<h2>\1<\/h2>/</p><p>s/^#\s*(.*)/<h1>\1<\/h1>/</p><p>s/^>\s*(.*)/<blockquote>\1<\/blockquote>/</p><p>t end</p><p>s/.+/<p>&<\/p>/</p><p>:end</p><p>$ {</p><p>x</p><p>/^```/ a\</p><p></pre></p><p>/^(\*|=>) / a\</p><p></ul></p><p>x</p><p>a\</p><p></body>\</p><p></html></p><p>}</p> <hr> <a href="https://codeberg.org/soap/gemini-bridge">Source</a> </main> </body> </html>