From c6e00afc7c23df994b70eee89d2d392718e6a321 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:09:42 +0100 Subject: [feature] tentatively start adding polls support (#2249) --- internal/text/plain.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'internal/text/plain.go') diff --git a/internal/text/plain.go b/internal/text/plain.go index 1456fd016..1935cec8c 100644 --- a/internal/text/plain.go +++ b/internal/text/plain.go @@ -21,6 +21,7 @@ import ( "bytes" "context" + "codeberg.org/gruf/go-byteutil" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/yuin/goldmark" @@ -103,11 +104,11 @@ func (f *Formatter) FromPlainEmojiOnly( statusID string, input string, ) *FormatResult { - // Initialize standard block parser - // that wraps result in
tags. + // Initialize block parser that + // doesn't wrap result in
tags. plainTextParser := parser.NewParser( parser.WithBlockParsers( - util.Prioritized(newPlaintextParser(), 500), + util.Prioritized(newPlaintextParserNoParagraph(), 500), ), ) @@ -161,17 +162,21 @@ func (f *Formatter) fromPlain( ), ) + // Convert input string to bytes + // without performing any allocs. + bInput := byteutil.S2B(input) + // Parse input into HTML. var htmlBytes bytes.Buffer if err := md.Convert( - []byte(input), + bInput, &htmlBytes, ); err != nil { log.Errorf(ctx, "error formatting plaintext input to HTML: %s", err) } // Clean and shrink HTML. - result.HTML = htmlBytes.String() + result.HTML = byteutil.B2S(htmlBytes.Bytes()) result.HTML = SanitizeToHTML(result.HTML) result.HTML = MinifyHTML(result.HTML) -- cgit v1.2.3