From 29eea1d83760642f177ffe2da30cdbed53d47683 Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 1 Dec 2022 19:43:59 +0100 Subject: [PATCH] don't escape notes --- embed/post-list.html | 2 +- renderer.go | 8 +++++++- renderer_test.go | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/embed/post-list.html b/embed/post-list.html index 6ff8985..29f5aa8 100644 --- a/embed/post-list.html +++ b/embed/post-list.html @@ -3,7 +3,7 @@
{{ if eq .Meta.Type "note"}} -

{{.RenderedContent}}

+

{{.RenderedContent | noescape}}

{{ else }}

{{ if .Title }}{{.Title}}{{ else }}{{.Id}}{{ end }} diff --git a/renderer.go b/renderer.go index 7e48087..f96ba39 100644 --- a/renderer.go +++ b/renderer.go @@ -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 } diff --git a/renderer_test.go b/renderer_test.go index 435340d..d21bcdc 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -148,6 +148,7 @@ func TestRenderNoteAsFullContent(t *testing.T) { Include: []string{"note"}, }) assertions.AssertContains(t, result, "This is a note") + assertions.AssertNotContains(t, result, "<p>This is a note") } func TestIndexPageContainsHFeedContainer(t *testing.T) {