summaryrefslogtreecommitdiff
path: root/internal/text
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-10-04 13:09:42 +0100
committerLibravatar GitHub <noreply@github.com>2023-10-04 13:09:42 +0100
commitc6e00afc7c23df994b70eee89d2d392718e6a321 (patch)
treecee98c1a78e36ba6a0e8183afa0b2796765fe7f6 /internal/text
parent[chore] internal/ap: add pollable AS types, code reformatting, general niceti... (diff)
downloadgotosocial-c6e00afc7c23df994b70eee89d2d392718e6a321.tar.xz
[feature] tentatively start adding polls support (#2249)
Diffstat (limited to 'internal/text')
-rw-r--r--internal/text/plain.go15
1 files changed, 10 insertions, 5 deletions
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 <p> tags.
+ // Initialize block parser that
+ // doesn't wrap result in <p> 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)