don't escape notes

This commit is contained in:
Niko Abeler 2022-12-01 19:43:59 +01:00
parent 48a11ab6d7
commit 29eea1d837
3 changed files with 9 additions and 2 deletions

View File

@ -3,7 +3,7 @@
<div class="h-entry">
<hgroup>
{{ if eq .Meta.Type "note"}}
<p>{{.RenderedContent}}</p>
<p>{{.RenderedContent | noescape}}</p>
{{ else }}
<h3><a class="u-url" href="{{.UrlPath}}">
{{ if .Title }}{{.Title}}{{ else }}{{.Id}}{{ end }}

View File

@ -45,6 +45,10 @@ type ErrorMessage struct {
Message string
}
func noescape(str string) template.HTML {
return template.HTML(str)
}
func renderEmbedTemplate(templateFile string, data interface{}) (string, error) {
templateStr, err := embed_files.ReadFile(templateFile)
if err != nil {
@ -54,7 +58,9 @@ func renderEmbedTemplate(templateFile string, data interface{}) (string, error)
}
func renderTemplateStr(templateStr []byte, data interface{}) (string, error) {
t, err := template.New("_").Parse(string(templateStr))
t, err := template.New("_").Funcs(template.FuncMap{
"noescape": noescape,
}).Parse(string(templateStr))
if err != nil {
return "", err
}

View File

@ -148,6 +148,7 @@ func TestRenderNoteAsFullContent(t *testing.T) {
Include: []string{"note"},
})
assertions.AssertContains(t, result, "This is a note")
assertions.AssertNotContains(t, result, "&lt;p&gt;This is a note")
}
func TestIndexPageContainsHFeedContainer(t *testing.T) {