summaryrefslogtreecommitdiff
path: root/internal/text/markdown.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-10-05 13:22:40 +0100
committerLibravatar GitHub <noreply@github.com>2023-10-05 13:22:40 +0100
commit6e508830e1ff98a6a0d525ebd967b80ff758ab59 (patch)
treee1a1462c60315584428da3e3037069e4a5546ae4 /internal/text/markdown.go
parent[docs] statuses-query-pinned #2250 (#2251) (diff)
downloadgotosocial-6e508830e1ff98a6a0d525ebd967b80ff758ab59.tar.xz
updates markdown parsing to reduce allocations in the same way as the plain text formatter (#2252)
Diffstat (limited to 'internal/text/markdown.go')
-rw-r--r--internal/text/markdown.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/internal/text/markdown.go b/internal/text/markdown.go
index 6fc1bd2f0..05d0a02f9 100644
--- a/internal/text/markdown.go
+++ b/internal/text/markdown.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"
@@ -65,17 +66,21 @@ func (f *Formatter) FromMarkdown(
),
)
+ // 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 markdown 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)