package main import ( "bytes" "fmt" "html" "io" "git.sr.ht/~adnano/gmi" ) // GeminiToHTML reads Gemini from the provided reader and returns an HTML string. func GeminiToHTML(r io.Reader) []byte { var b bytes.Buffer var pre bool var list bool b.WriteString("\n") text := gmi.Parse(r) for _, l := range text { if _, ok := l.(gmi.LineListItem); ok { if !list { list = true b.WriteString("
\n") } else { b.WriteString("\n") } case gmi.LinePreformattedText: text := string(l.(gmi.LinePreformattedText)) fmt.Fprintf(&b, "%s\n", html.EscapeString(text)) case gmi.LineHeading1: text := string(l.(gmi.LineHeading1)) fmt.Fprintf(&b, "
%s\n", html.EscapeString(text)) case gmi.LineText: text := string(l.(gmi.LineText)) fmt.Fprintf(&b, "
%s
\n", html.EscapeString(text)) } } return b.Bytes() }