+10
-4
appview/pages/funcmap.go
+10
-4
appview/pages/funcmap.go
···
19
20
"github.com/dustin/go-humanize"
21
"github.com/go-enry/go-enry/v2"
22
-
"github.com/microcosm-cc/bluemonday"
23
"tangled.sh/tangled.sh/core/appview/filetree"
24
"tangled.sh/tangled.sh/core/appview/pages/markup"
25
)
···
207
}
208
return v.Slice(0, min(n, v.Len())).Interface()
209
},
210
-
211
"markdown": func(text string) template.HTML {
212
-
rctx := &markup.RenderContext{RendererType: markup.RendererTypeDefault}
213
-
return template.HTML(bluemonday.UGCPolicy().Sanitize(rctx.RenderMarkdown(text)))
214
},
215
"isNil": func(t any) bool {
216
// returns false for other "zero" values
···
19
20
"github.com/dustin/go-humanize"
21
"github.com/go-enry/go-enry/v2"
22
"tangled.sh/tangled.sh/core/appview/filetree"
23
"tangled.sh/tangled.sh/core/appview/pages/markup"
24
)
···
206
}
207
return v.Slice(0, min(n, v.Len())).Interface()
208
},
209
"markdown": func(text string) template.HTML {
210
+
p.rctx.RendererType = markup.RendererTypeDefault
211
+
htmlString := p.rctx.RenderMarkdown(text)
212
+
sanitized := p.rctx.SanitizeDefault(htmlString)
213
+
return template.HTML(sanitized)
214
+
},
215
+
"description": func(text string) template.HTML {
216
+
p.rctx.RendererType = markup.RendererTypeDefault
217
+
htmlString := p.rctx.RenderMarkdown(text)
218
+
sanitized := p.rctx.SanitizeDescription(htmlString)
219
+
return template.HTML(sanitized)
220
},
221
"isNil": func(t any) bool {
222
// returns false for other "zero" values
+4
appview/pages/markup/markdown.go
+4
appview/pages/markup/markdown.go
+20
-2
appview/pages/markup/sanitizer.go
+20
-2
appview/pages/markup/sanitizer.go
···
11
)
12
13
type Sanitizer struct {
14
+
defaultPolicy *bluemonday.Policy
15
+
descriptionPolicy *bluemonday.Policy
16
}
17
18
func NewSanitizer() Sanitizer {
19
return Sanitizer{
20
+
defaultPolicy: defaultPolicy(),
21
+
descriptionPolicy: descriptionPolicy(),
22
}
23
}
24
···
92
93
return policy
94
}
95
+
96
+
func descriptionPolicy() *bluemonday.Policy {
97
+
policy := bluemonday.NewPolicy()
98
+
policy.AllowStandardURLs()
99
+
100
+
// allow italics and bold.
101
+
policy.AllowElements("i", "b", "em", "strong")
102
+
103
+
// allow code.
104
+
policy.AllowElements("code")
105
+
106
+
// allow links
107
+
policy.AllowAttrs("href", "target", "rel").OnElements("a")
108
+
109
+
return policy
110
+
}
+1
-1
appview/pages/templates/repo/issues/issue.html
+1
-1
appview/pages/templates/repo/issues/issue.html
+1
-1
appview/pages/templates/repo/issues/issues.html
+1
-1
appview/pages/templates/repo/issues/issues.html
+1
-1
appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html
+1
-1
appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html
+1
-1
appview/pages/templates/repo/pulls/pull.html
+1
-1
appview/pages/templates/repo/pulls/pull.html
+1
-1
appview/pages/templates/repo/pulls/pulls.html
+1
-1
appview/pages/templates/repo/pulls/pulls.html