Skip to content

Commit

Permalink
template(question): <br> in question
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Aug 31, 2024
1 parent 68ee092 commit c16d2e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "</br>")
return template.HTML(input)
},
"AnswerFormat": func(input string) template.HTML {
input = html.EscapeString(input)
input = strings.ReplaceAll(input, "\n", "</br>")
Expand Down
2 changes: 1 addition & 1 deletion templates/question/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="uk-card uk-card-default">
<div class="uk-card-header">
<div class="uk-text-left uk-text-small uk-text-muted">{{Date .Question.CreatedAt "Y-m-d H:i:s"}}</div>
<h4 class="uk-text-center uk-margin-top uk-margin-bottom uk-text-break">{{.Question.Content}}</h4>
<h4 class="uk-text-center uk-margin-top uk-margin-bottom uk-text-break">{{QuestionFormat .Question.Content}}</h4>
{{ if .AskUploadImages }}
<ul class="uk-thumbnav" uk-margin>
{{ range $index, $elem := .AskUploadImages }}
Expand Down

0 comments on commit c16d2e3

Please sign in to comment.