personal-website/libs/markdown.go

32 lines
742 B
Go
Raw Normal View History

2023-06-06 22:49:26 +00:00
package libs
import (
2023-06-06 23:17:29 +00:00
"html/template"
2023-06-07 00:42:50 +00:00
"strings"
2023-06-06 23:17:29 +00:00
2023-06-06 22:49:26 +00:00
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday/v2"
)
type MarkdownLib struct {
}
2023-06-07 00:42:50 +00:00
func (ml *MarkdownLib) Render(md []byte, supressParagraph bool) template.HTML {
output := blackfriday.Run(md)
if supressParagraph {
output = []byte(strings.ReplaceAll(string(output), "<p>", ""))
output = []byte(strings.ReplaceAll(string(output), "</p>", ""))
}
2023-06-06 22:49:26 +00:00
_ = output
html := bluemonday.UGCPolicy().SanitizeBytes(output)
// println(string(html))
2023-06-06 23:17:29 +00:00
kek := template.HTML(html)
return kek
2023-06-06 22:49:26 +00:00
}
2023-06-06 23:17:29 +00:00
// func (ml MarkdownLib) MarkDowner(args ...interface{}) template.HTML {
// s := blackfriday.MarkdownCommon([]byte(fmt.Sprintf("%s", args...)))
// return template.HTML(s)
// }