From 14ed5a502038ae8a6833c412c94b4fbfe06648a3 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sun, 14 May 2017 15:01:12 +0200 Subject: [PATCH] Change motion content formatting Use a linebreak sensitive paragraph instead of
 for motion content
output.
---
 boardvoting.go                  | 6 +++++-
 templates/motion_fragments.html | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/boardvoting.go b/boardvoting.go
index c93709c..3b62116 100644
--- a/boardvoting.go
+++ b/boardvoting.go
@@ -40,7 +40,11 @@ func getTemplateFilenames(templates []string) (result []string) {
 }
 
 func renderTemplate(w http.ResponseWriter, templates []string, context interface{}) {
-	t := template.Must(template.New(templates[0]).Funcs(sprig.FuncMap()).ParseFiles(getTemplateFilenames(templates)...))
+	funcMaps := sprig.FuncMap()
+	funcMaps["nl2br"] = func(text string) template.HTML {
+		return template.HTML(strings.Replace(template.HTMLEscapeString(text), "\n", "
", -1)) + } + t := template.Must(template.New(templates[0]).Funcs(funcMaps).ParseFiles(getTemplateFilenames(templates)...)) if err := t.Execute(w, context); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } diff --git a/templates/motion_fragments.html b/templates/motion_fragments.html index ed036d7..dbe59c2 100644 --- a/templates/motion_fragments.html +++ b/templates/motion_fragments.html @@ -2,7 +2,7 @@ {{ .Status|toString|title }} {{ .Modified|date "2006-01-02 15:04:05 UTC" }}

{{ .Tag }}: {{ .Title }}

-
{{ wrap 76 .Content }}
+

{{ wrap 76 .Content | nl2br }}