···
"github.com/microcosm-cc/bluemonday"
···
RendererType RendererType
func (rctx *RenderContext) RenderMarkdown(source string) string {
···
-
func (rctx *RenderContext) Sanitize(html string) string {
policy := bluemonday.UGCPolicy()
-
policy.AllowElements("video")
-
policy.AllowAttrs("controls").OnElements("video")
-
policy.AllowElements("source")
-
policy.AllowAttrs("src", "type").OnElements("source")
policy.AllowElements("center")
···
-
return policy.Sanitize(html)
type MarkdownTransformer struct {
···
"github.com/microcosm-cc/bluemonday"
···
RendererType RendererType
+
type Sanitizer struct {
+
defaultPolicy *bluemonday.Policy
func (rctx *RenderContext) RenderMarkdown(source string) string {
···
+
func (rctx *RenderContext) SanitizeDefault(html string) string {
+
return rctx.Sanitizer.defaultPolicy.Sanitize(html)
+
func NewSanitizer() Sanitizer {
+
defaultPolicy: defaultPolicy(),
+
func defaultPolicy() *bluemonday.Policy {
policy := bluemonday.UGCPolicy()
+
// Allow generally safe attributes
+
generalSafeAttrs := []string{
+
"abbr", "accept", "accept-charset",
+
"accesskey", "action", "align", "alt",
+
"aria-describedby", "aria-hidden", "aria-label", "aria-labelledby",
+
"axis", "border", "cellpadding", "cellspacing", "char",
+
"charoff", "charset", "checked",
+
"clear", "cols", "colspan", "color",
+
"compact", "coords", "datetime", "dir",
+
"disabled", "enctype", "for", "frame",
+
"headers", "height", "hreflang",
+
"hspace", "ismap", "label", "lang",
+
"maxlength", "media", "method",
+
"multiple", "name", "nohref", "noshade",
+
"nowrap", "open", "prompt", "readonly", "rel", "rev",
+
"rows", "rowspan", "rules", "scope",
+
"selected", "shape", "size", "span",
+
"start", "summary", "tabindex", "target",
+
"title", "type", "usemap", "valign", "value",
+
"vspace", "width", "itemprop",
+
generalSafeElements := []string{
+
"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "br", "b", "i", "strong", "em", "a", "pre", "code", "img", "tt",
+
"div", "ins", "del", "sup", "sub", "p", "ol", "ul", "table", "thead", "tbody", "tfoot", "blockquote", "label",
+
"dl", "dt", "dd", "kbd", "q", "samp", "var", "hr", "ruby", "rt", "rp", "li", "tr", "td", "th", "s", "strike", "summary",
+
"details", "caption", "figure", "figcaption",
+
"abbr", "bdo", "cite", "dfn", "mark", "small", "span", "time", "video", "wbr",
+
policy.AllowAttrs(generalSafeAttrs...).OnElements(generalSafeElements...)
+
policy.AllowAttrs("src", "autoplay", "controls").OnElements("video")
+
policy.AllowAttrs("type").Matching(regexp.MustCompile(`^checkbox$`)).OnElements("input")
+
policy.AllowAttrs("checked", "disabled", "data-source-position").OnElements("input")
policy.AllowElements("center")
···
type MarkdownTransformer struct {