@@ -28,20 +28,26 @@ var sanitizer = &Sanitizer{}
2828// entire application lifecycle.
2929func NewSanitizer () {
3030 sanitizer .init .Do (func () {
31- sanitizer . policy = bluemonday . UGCPolicy ()
32- // We only want to allow HighlightJS specific classes for code blocks
33- sanitizer . policy . AllowAttrs ( "class" ). Matching ( regexp . MustCompile ( `^language-\w+$` )). OnElements ( "code" )
31+ ReplaceSanitizer ()
32+ })
33+ }
3434
35- // Checkboxes
36- sanitizer .policy .AllowAttrs ("type" ).Matching (regexp .MustCompile (`^checkbox$` )).OnElements ("input" )
37- sanitizer .policy .AllowAttrs ("checked" , "disabled" ).OnElements ("input" )
35+ // ReplaceSanitizer replaces the current sanitizer to account for changes in settings
36+ func ReplaceSanitizer () {
37+ sanitizer = & Sanitizer {}
38+ sanitizer .policy = bluemonday .UGCPolicy ()
39+ // We only want to allow HighlightJS specific classes for code blocks
40+ sanitizer .policy .AllowAttrs ("class" ).Matching (regexp .MustCompile (`^language-\w+$` )).OnElements ("code" )
3841
39- // Custom URL-Schemes
40- sanitizer .policy .AllowURLSchemes (setting .Markdown .CustomURLSchemes ... )
42+ // Checkboxes
43+ sanitizer .policy .AllowAttrs ("type" ).Matching (regexp .MustCompile (`^checkbox$` )).OnElements ("input" )
44+ sanitizer .policy .AllowAttrs ("checked" , "disabled" ).OnElements ("input" )
4145
42- // Allow keyword markup
43- sanitizer .policy .AllowAttrs ("class" ).Matching (regexp .MustCompile (`^` + keywordClass + `$` )).OnElements ("span" )
44- })
46+ // Custom URL-Schemes
47+ sanitizer .policy .AllowURLSchemes (setting .Markdown .CustomURLSchemes ... )
48+
49+ // Allow keyword markup
50+ sanitizer .policy .AllowAttrs ("class" ).Matching (regexp .MustCompile (`^` + keywordClass + `$` )).OnElements ("span" )
4551}
4652
4753// Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
0 commit comments