diff options
Diffstat (limited to 'internal/text/plain.go')
-rw-r--r-- | internal/text/plain.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/internal/text/plain.go b/internal/text/plain.go index 453f4dd31..4ef3b3715 100644 --- a/internal/text/plain.go +++ b/internal/text/plain.go @@ -20,12 +20,17 @@ package text import ( "context" - "fmt" "strings" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) +// breakReplacer replaces new-lines with HTML breaks. +var breakReplacer = strings.NewReplacer( + "\r\n", "<br/>", + "\n", "<br/>", +) + func (f *formatter) FromPlain(ctx context.Context, plain string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string { content := preformat(plain) @@ -42,10 +47,10 @@ func (f *formatter) FromPlain(ctx context.Context, plain string, mentions []*gts content = f.ReplaceMentions(ctx, content, mentions) // replace newlines with breaks - content = strings.ReplaceAll(content, "\n", "<br />") + content = breakReplacer.Replace(content) // wrap the whole thing in a pee - content = fmt.Sprintf(`<p>%s</p>`, content) + content = `<p>` + content + `</p>` return postformat(content) } |