package main import ( "bytes" "fmt" "html" "git.sr.ht/~adnano/gmi" ) // gmiToHTML converts the provided Gemini text to HTML. func gmiToHTML(text gmi.Text) []byte { var b bytes.Buffer var pre bool var list bool for _, l := range text { if _, ok := l.(gmi.LineListItem); ok { if !list { list = true fmt.Fprint(&b, "\n") } switch l.(type) { case gmi.LineLink: link := l.(gmi.LineLink) url := html.EscapeString(link.URL) name := html.EscapeString(link.Name) if name == "" { name = url } fmt.Fprintf(&b, "

%s

\n", url, name) case gmi.LinePreformattingToggle: pre = !pre if pre { fmt.Fprint(&b, "
\n")
			} else {
				fmt.Fprint(&b, "
\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.LineHeading2: text := string(l.(gmi.LineHeading2)) fmt.Fprintf(&b, "

%s

\n", html.EscapeString(text)) case gmi.LineHeading3: text := string(l.(gmi.LineHeading3)) fmt.Fprintf(&b, "

%s

\n", html.EscapeString(text)) case gmi.LineListItem: text := string(l.(gmi.LineListItem)) fmt.Fprintf(&b, "
  • %s
  • \n", html.EscapeString(text)) case gmi.LineQuote: text := string(l.(gmi.LineQuote)) fmt.Fprintf(&b, "
    %s
    \n", html.EscapeString(text)) case gmi.LineText: text := string(l.(gmi.LineText)) if text == "" { fmt.Fprint(&b, "
    \n") } else { fmt.Fprintf(&b, "

    %s

    \n", html.EscapeString(text)) } } } if pre { fmt.Fprint(&b, "\n") } if list { fmt.Fprint(&b, "\n") } return b.Bytes() }