Woops
Greater-than symbols were being filtered out by the sanitizer as they were saved to the database. Hopefully this will fix 'em. I considered using regexp, but thought that would be complete overkill.
Cette révision appartient à :
Parent
40b3fddc24
révision
d79ae33e0e
1 fichiers modifiés avec 27 ajouts et 2 suppressions
|
@ -2,14 +2,39 @@ package util
|
|||
|
||||
import (
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/russross/blackfriday"
|
||||
md "github.com/russross/blackfriday"
|
||||
|
||||
"html/template"
|
||||
"strings"
|
||||
)
|
||||
//Some default rules, plus and minus some.
|
||||
var mdOptions = 0 |
|
||||
md.EXTENSION_AUTOLINK |
|
||||
md.EXTENSION_HARD_LINE_BREAK |
|
||||
md.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK |
|
||||
md.EXTENSION_NO_INTRA_EMPHASIS |
|
||||
md.EXTENSION_SPACE_HEADERS |
|
||||
md.EXTENSION_STRIKETHROUGH
|
||||
|
||||
var htmlFlags = 0 |
|
||||
md.HTML_USE_XHTML |
|
||||
md.HTML_SMARTYPANTS_FRACTIONS |
|
||||
md.HTML_SAFELINK |
|
||||
md.HTML_NOREFERRER_LINKS |
|
||||
md.HTML_HREF_TARGET_BLANK
|
||||
|
||||
func init() {
|
||||
HtmlMdRenderer = md.HtmlRenderer(htmlFlags, "", "")
|
||||
}
|
||||
var HtmlMdRenderer md.Renderer
|
||||
|
||||
// TODO: restrict certain types of markdown
|
||||
func MarkdownToHTML(markdown string) template.HTML {
|
||||
unsafe := blackfriday.MarkdownCommon([]byte(markdown))
|
||||
if len(markdown) >= 3) && markdown[:3] == ">" {
|
||||
markdown = ">" + markdown[3:]
|
||||
}
|
||||
markdown = strings.Replace(markdown,"\n>","\n>")
|
||||
unsafe := md.MarkdownOptions([]byte(markdown), HtmlMdRenderer, md.Options{Extensions: mdOptions})
|
||||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
|
||||
return template.HTML(html)
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket