Change structure of code to a frontend and backend one
This commit is contained in:
35
cmd/backend/markdown.go
Normal file
35
cmd/backend/markdown.go
Normal file
@ -0,0 +1,35 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/yuin/goldmark"
|
||||
)
|
||||
|
||||
func ConvertToHTML(md string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
||||
}
|
||||
|
||||
p := bluemonday.UGCPolicy()
|
||||
html := p.Sanitize(buf.String())
|
||||
|
||||
return html, nil
|
||||
}
|
||||
|
||||
func ConvertToPlain(md string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := goldmark.Convert([]byte(md), &buf); err != nil {
|
||||
return "", fmt.Errorf("error converting markdown to html: %v", err)
|
||||
}
|
||||
|
||||
p := bluemonday.StrictPolicy()
|
||||
plain := p.Sanitize(buf.String())
|
||||
|
||||
return plain, nil
|
||||
}
|
Reference in New Issue
Block a user