@@ -11,7 +11,6 @@ import (
11
11
"github.com/google/safehtml"
12
12
"github.com/google/safehtml/template"
13
13
"github.com/google/safehtml/uncheckedconversions"
14
- "github.com/microcosm-cc/bluemonday"
15
14
"github.com/yuin/goldmark"
16
15
emoji "github.com/yuin/goldmark-emoji"
17
16
"github.com/yuin/goldmark/extension"
@@ -23,6 +22,7 @@ import (
23
22
"golang.org/x/pkgsite/internal"
24
23
"golang.org/x/pkgsite/internal/derrors"
25
24
"golang.org/x/pkgsite/internal/log"
25
+ "golang.org/x/pkgsite/internal/sanitizer"
26
26
"golang.org/x/pkgsite/internal/source"
27
27
)
28
28
@@ -112,7 +112,7 @@ func processReadme(ctx context.Context, readme *internal.Readme, sourceInfo *sou
112
112
),
113
113
),
114
114
// These extensions lets users write HTML code in the README. This is
115
- // fine since we process the contents using bluemonday after.
115
+ // fine since we process the contents using the sanitizer after.
116
116
goldmark .WithRendererOptions (goldmarkHtml .WithUnsafe (), goldmarkHtml .WithXHTML ()),
117
117
goldmark .WithExtensions (
118
118
extension .GFM , // Support Github Flavored Markdown.
@@ -159,18 +159,6 @@ func processReadme(ctx context.Context, readme *internal.Readme, sourceInfo *sou
159
159
160
160
// sanitizeHTML sanitizes HTML from a bytes.Buffer so that it is safe.
161
161
func sanitizeHTML (b * bytes.Buffer ) safehtml.HTML {
162
- p := bluemonday .UGCPolicy ()
163
-
164
- p .AllowAttrs ("width" , "align" ).OnElements ("img" )
165
- p .AllowAttrs ("width" , "align" ).OnElements ("div" )
166
- p .AllowAttrs ("width" , "align" ).OnElements ("p" )
167
- // Allow accessible headings (i.e <div role="heading" aria-level="7">).
168
- p .AllowAttrs ("width" , "align" , "role" , "aria-level" ).OnElements ("div" )
169
- for _ , h := range []string {"h1" , "h2" , "h3" , "h4" , "h5" , "h6" } {
170
- // Needed to preserve github styles heading font-sizes
171
- p .AllowAttrs ("class" ).OnElements (h )
172
- }
173
-
174
- s := string (p .SanitizeBytes (b .Bytes ()))
162
+ s := string (sanitizer .SanitizeBytes (b .Bytes ()))
175
163
return uncheckedconversions .HTMLFromStringKnownToSatisfyTypeContract (s )
176
164
}
0 commit comments