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