Added HTML sanitizer
This commit is contained in:
parent
5d41543543
commit
ebfe01069c
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/microcosm-cc/bluemonday"
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,8 +12,11 @@ func ConvertToHTML(md string) (string, error) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||||
return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err)
|
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.String(), nil
|
p := bluemonday.UGCPolicy()
|
||||||
|
html := p.Sanitize(buf.String())
|
||||||
|
|
||||||
|
return html, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user