2022-08-11 03:59:59 +00:00
|
|
|
// Package markdown provides markdown render functions.
|
|
|
|
package markdown
|
|
|
|
|
|
|
|
import (
|
2022-08-24 05:55:19 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-08-11 03:59:59 +00:00
|
|
|
"github.com/microcosm-cc/bluemonday"
|
|
|
|
"github.com/shurcooL/github_flavored_markdown"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Render markdown from untrusted sources.
|
|
|
|
func Render(input string) string {
|
|
|
|
// Render Markdown to HTML.
|
|
|
|
html := github_flavored_markdown.Markdown([]byte(input))
|
|
|
|
|
|
|
|
// Sanitize the HTML from any nasties.
|
|
|
|
p := bluemonday.UGCPolicy()
|
|
|
|
safened := p.SanitizeBytes(html)
|
|
|
|
return string(safened)
|
|
|
|
}
|
2022-08-24 05:55:19 +00:00
|
|
|
|
|
|
|
// Quotify a message putting it into a Markdown "> quotes" block.
|
|
|
|
func Quotify(input string) string {
|
|
|
|
var lines = []string{}
|
|
|
|
for _, line := range strings.Split(input, "\n") {
|
|
|
|
lines = append(lines, "> "+line)
|
|
|
|
}
|
|
|
|
return strings.Join(lines, "\n")
|
|
|
|
}
|