~adnano/gmnitohtml

332368e55341b8de44eecd5abe128d4a4b6a3087 — Adnan Maolood 1 year, 2 months ago 58cd619 0.1.0
Insert breaks for multiple consecutive blank lines

Insert <br> tags for consecutive blank lines, ignoring the first blank
line.
1 files changed, 13 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +13 -1
@@ 66,6 66,7 @@ type HTMLWriter struct {
	out  io.Writer
	pre  bool
	list bool
	br   bool
}

func (h *HTMLWriter) Handle(line gemini.Line) {


@@ 78,6 79,7 @@ func (h *HTMLWriter) Handle(line gemini.Line) {
		h.list = false
		fmt.Fprint(h.out, "</ul>\n")
	}
	var blank bool
	switch line := line.(type) {
	case gemini.LineLink:
		url := html.EscapeString(line.URL)


@@ 112,10 114,20 @@ func (h *HTMLWriter) Handle(line gemini.Line) {
	case gemini.LineQuote:
		fmt.Fprintf(h.out, "<blockquote>%s</blockquote>\n", html.EscapeString(string(line)))
	case gemini.LineText:
		if line != "" {
		if line == "" {
			blank = true
			if h.br {
				fmt.Fprint(h.out, "<br>\n")
			} else {
				h.br = true
			}
		} else {
			fmt.Fprintf(h.out, "<p>%s</p>\n", html.EscapeString(string(line)))
		}
	}
	if h.br && !blank {
		h.br = false
	}
}

func (h *HTMLWriter) Finish() {