From 35b41689357b3905de5ede182b92a3b06e05558c Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 10 Nov 2020 20:15:55 +0500 Subject: [PATCH] Comply with Gemini spec p. 5.4.1 This part of spec says soft text wrapping is preferred to hard wrapping, to comply with that we replace the newlines in raw Markdown text with spaces. --- internal/gemini/renderer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/gemini/renderer.go b/internal/gemini/renderer.go index a3543d4..be8ade3 100644 --- a/internal/gemini/renderer.go +++ b/internal/gemini/renderer.go @@ -22,6 +22,7 @@ import ( "bytes" "fmt" "io" + "strings" "time" "github.com/gomarkdown/markdown/ast" @@ -266,7 +267,9 @@ func (r Renderer) list(w io.Writer, node *ast.List, level int) { func (r Renderer) text(w io.Writer, node ast.Node) { if node := node.AsLeaf(); node != nil { - w.Write(node.Literal) + // replace all newlines in text with spaces, allowing for soft + // wrapping; this is recommended as per Gemini spec p. 5.4.1 + w.Write([]byte(strings.ReplaceAll(string(node.Literal), "\n", " "))) } }