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 }}