diff --git a/examples/html.go b/examples/html.go index fe59c87..bb99c56 100644 --- a/examples/html.go +++ b/examples/html.go @@ -37,11 +37,10 @@ func textToHTML(text gemini.Text) string { list = false fmt.Fprint(&b, "\n") } - switch l.(type) { + switch l := l.(type) { case gemini.LineLink: - link := l.(gemini.LineLink) - url := html.EscapeString(link.URL) - name := html.EscapeString(link.Name) + url := html.EscapeString(l.URL) + name := html.EscapeString(l.Name) if name == "" { name = url } @@ -54,29 +53,22 @@ func textToHTML(text gemini.Text) string { fmt.Fprint(&b, "\n") } case gemini.LinePreformattedText: - text := string(l.(gemini.LinePreformattedText)) - fmt.Fprintf(&b, "%s\n", html.EscapeString(text)) + fmt.Fprintf(&b, "%s\n", html.EscapeString(string(l))) case gemini.LineHeading1: - text := string(l.(gemini.LineHeading1)) - fmt.Fprintf(&b, "

%s

\n", html.EscapeString(text)) + fmt.Fprintf(&b, "

%s

\n", html.EscapeString(string(l))) case gemini.LineHeading2: - text := string(l.(gemini.LineHeading2)) - fmt.Fprintf(&b, "

%s

\n", html.EscapeString(text)) + fmt.Fprintf(&b, "

%s

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

%s

\n", html.EscapeString(text)) + fmt.Fprintf(&b, "

%s

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

    %s

    \n", html.EscapeString(text)) + fmt.Fprintf(&b, "

    %s

    \n", html.EscapeString(string(l))) } } }