Noah Petherbridge
a663462e27
Adds initial code for basically functional forums: * Forums landing page shows hard-coded list of Categories along with any forums in the DB that use those categories. * Admin: Create, Edit forums and view forums you own or have admin rights to modify. * Landing page forums list shows the title/description and dynamic count of number of Topics and total number of Posts in each forum. TODO: distinct count of Users who posted in each forum. * Board Index page shows list of Threads (posts) with a Replies count and Views count on each thread. * Thread view is basically an array of Comments. Users can post, edit and delete (their own) comments. Deleting the first comment removes the entire Thread - the thread points to a first Comment to provide its body. * Reply and Quote-Reply options working.
30 lines
731 B
Go
30 lines
731 B
Go
// Package markdown provides markdown render functions.
|
|
package markdown
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"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)
|
|
}
|
|
|
|
// 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")
|
|
}
|