[feature] Allow footnotes in markdown, use <br> instead of \n (#767)

* allow markdown footnotes + hard line breaks

* don't keep whitespace w/minify (unnecessary now)

* test markdown a bit more
This commit is contained in:
tobi 2022-08-26 13:28:06 +02:00 committed by GitHub
commit 79fb8bad04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View file

@ -28,7 +28,10 @@ import (
"github.com/tdewolff/minify/v2/html"
)
var m *minify.M
var (
bfExtensions = blackfriday.CommonExtensions | blackfriday.HardLineBreak | blackfriday.Footnotes
m *minify.M
)
func (f *formatter) FromMarkdown(ctx context.Context, md string, mentions []*gtsmodel.Mention, tags []*gtsmodel.Tag) string {
// format tags nicely
@ -38,7 +41,7 @@ func (f *formatter) FromMarkdown(ctx context.Context, md string, mentions []*gts
content = f.ReplaceMentions(ctx, content, mentions)
// parse markdown
contentBytes := blackfriday.Run([]byte(content))
contentBytes := blackfriday.Run([]byte(content), blackfriday.WithExtensions(bfExtensions))
// clean anything dangerous out of it
content = SanitizeHTML(string(contentBytes))
@ -46,9 +49,8 @@ func (f *formatter) FromMarkdown(ctx context.Context, md string, mentions []*gts
if m == nil {
m = minify.New()
m.Add("text/html", &html.Minifier{
KeepEndTags: true,
KeepQuotes: true,
KeepWhitespace: true,
KeepEndTags: true,
KeepQuotes: true,
})
}