@@ -28,20 +28,26 @@ var sanitizer = &Sanitizer{}
28
28
// entire application lifecycle.
29
29
func NewSanitizer () {
30
30
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
+ }
34
34
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" )
38
41
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" )
41
45
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" )
45
51
}
46
52
47
53
// Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.
0 commit comments