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.
This commit is contained in:
Timur Demin 2020-11-10 20:15:55 +05:00
parent 637ff4b71b
commit 35b4168935
No known key found for this signature in database
GPG key ID: 9EDF3F9D9286FA20

View file

@ -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", " ")))
}
}