forked from tangled.org/core
this repo has no description

wip: render markdown subset in issue/PR titles

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li d499aa0f dfc91bcd

verified
Changed files
+39 -11
appview
+10 -4
appview/pages/funcmap.go
···
"github.com/dustin/go-humanize"
"github.com/go-enry/go-enry/v2"
-
"github.com/microcosm-cc/bluemonday"
"tangled.sh/tangled.sh/core/appview/filetree"
"tangled.sh/tangled.sh/core/appview/pages/markup"
)
···
}
return v.Slice(0, min(n, v.Len())).Interface()
},
-
"markdown": func(text string) template.HTML {
-
rctx := &markup.RenderContext{RendererType: markup.RendererTypeDefault}
-
return template.HTML(bluemonday.UGCPolicy().Sanitize(rctx.RenderMarkdown(text)))
+
p.rctx.RendererType = markup.RendererTypeDefault
+
htmlString := p.rctx.RenderMarkdown(text)
+
sanitized := p.rctx.SanitizeDefault(htmlString)
+
return template.HTML(sanitized)
+
},
+
"description": func(text string) template.HTML {
+
p.rctx.RendererType = markup.RendererTypeDefault
+
htmlString := p.rctx.RenderMarkdown(text)
+
sanitized := p.rctx.SanitizeDescription(htmlString)
+
return template.HTML(sanitized)
},
"isNil": func(t any) bool {
// returns false for other "zero" values
+4
appview/pages/markup/markdown.go
···
return rctx.Sanitizer.defaultPolicy.Sanitize(html)
}
+
func (rctx *RenderContext) SanitizeDescription(html string) string {
+
return rctx.Sanitizer.descriptionPolicy.Sanitize(html)
+
}
+
type MarkdownTransformer struct {
rctx *RenderContext
}
+20 -2
appview/pages/markup/sanitizer.go
···
)
type Sanitizer struct {
-
defaultPolicy *bluemonday.Policy
+
defaultPolicy *bluemonday.Policy
+
descriptionPolicy *bluemonday.Policy
}
func NewSanitizer() Sanitizer {
return Sanitizer{
-
defaultPolicy: defaultPolicy(),
+
defaultPolicy: defaultPolicy(),
+
descriptionPolicy: descriptionPolicy(),
}
}
···
return policy
}
+
+
func descriptionPolicy() *bluemonday.Policy {
+
policy := bluemonday.NewPolicy()
+
policy.AllowStandardURLs()
+
+
// allow italics and bold.
+
policy.AllowElements("i", "b", "em", "strong")
+
+
// allow code.
+
policy.AllowElements("code")
+
+
// allow links
+
policy.AllowAttrs("href", "target", "rel").OnElements("a")
+
+
return policy
+
}
+1 -1
appview/pages/templates/repo/issues/issue.html
···
{{ define "repoContent" }}
<header class="pb-4">
<h1 class="text-2xl">
-
{{ .Issue.Title }}
+
{{ .Issue.Title | description }}
<span class="text-gray-500 dark:text-gray-400">
#{{ .Issue.IssueId }}
</span>
+1 -1
appview/pages/templates/repo/issues/issues.html
···
<a
href="/{{ $.RepoInfo.FullName }}/issues/{{ .IssueId }}"
class="no-underline hover:underline">
-
{{ .Title }}
+
{{ .Title | description }}
<span class="text-gray-500">#{{ .IssueId }}</span>
</a>
</div>
+1 -1
appview/pages/templates/repo/pulls/fragments/summarizedPullHeader.html
···
</div>
<span class="truncate text-sm text-gray-800 dark:text-gray-200">
<span class="text-gray-500 dark:text-gray-400">#{{ .PullId }}</span>
-
{{ .Title }}
+
{{ .Title | description }}
</span>
</div>
+1 -1
appview/pages/templates/repo/pulls/pull.html
···
{{ end }}
</div>
<div class="flex items-center">
-
<span>{{ .Title }}</span>
+
<span>{{ .Title | description }}</span>
{{ if gt (len .Body) 0 }}
<button
class="py-1/2 px-1 mx-2 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
+1 -1
appview/pages/templates/repo/pulls/pulls.html
···
<a
href="/{{ $.RepoInfo.FullName }}/pulls/{{ .PullId }}"
class="dark:text-white">
-
{{ .Title }}
+
{{ .Title | description }}
<span class="text-gray-500 dark:text-gray-400">
#{{ .PullId }}
</span>