From c16d2e3c3b5b9de155bd770f2420e7c21350a2d7 Mon Sep 17 00:00:00 2001 From: E99p1ant Date: Sat, 31 Aug 2024 22:30:29 +0800 Subject: [PATCH] template(question):
in question --- internal/template/template.go | 5 +++++ templates/question/item.html | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/template/template.go b/internal/template/template.go index 0038611..fdc2368 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -42,6 +42,11 @@ func FuncMap() []template.FuncMap { format = replacer.Replace(format) return t.Format(format) }, + "QuestionFormat": func(input string) template.HTML { + input = html.EscapeString(input) + input = strings.ReplaceAll(input, "\n", "
") + return template.HTML(input) + }, "AnswerFormat": func(input string) template.HTML { input = html.EscapeString(input) input = strings.ReplaceAll(input, "\n", "
") diff --git a/templates/question/item.html b/templates/question/item.html index 3380433..7a96ff9 100644 --- a/templates/question/item.html +++ b/templates/question/item.html @@ -9,7 +9,7 @@
{{Date .Question.CreatedAt "Y-m-d H:i:s"}}
-

{{.Question.Content}}

+

{{QuestionFormat .Question.Content}}

{{ if .AskUploadImages }}
    {{ range $index, $elem := .AskUploadImages }}