mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00:00
updates markdown parsing to reduce allocations in the same way as the plain text formatter (#2252)
This commit is contained in:
parent
e0f0d320f6
commit
6e508830e1
1 changed files with 7 additions and 2 deletions
|
@ -21,6 +21,7 @@
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"codeberg.org/gruf/go-byteutil"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/yuin/goldmark"
|
"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.
|
// Parse input into HTML.
|
||||||
var htmlBytes bytes.Buffer
|
var htmlBytes bytes.Buffer
|
||||||
if err := md.Convert(
|
if err := md.Convert(
|
||||||
[]byte(input),
|
bInput,
|
||||||
&htmlBytes,
|
&htmlBytes,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Errorf(ctx, "error formatting markdown input to HTML: %s", err)
|
log.Errorf(ctx, "error formatting markdown input to HTML: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean and shrink HTML.
|
// Clean and shrink HTML.
|
||||||
result.HTML = htmlBytes.String()
|
result.HTML = byteutil.B2S(htmlBytes.Bytes())
|
||||||
result.HTML = SanitizeToHTML(result.HTML)
|
result.HTML = SanitizeToHTML(result.HTML)
|
||||||
result.HTML = MinifyHTML(result.HTML)
|
result.HTML = MinifyHTML(result.HTML)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue