Commits

Ian Lewis committed cc35c2c

Change newlines to <br> tags

Comments (0)

Files changed (2)

     }
 }
 
+func newlineFormatter(wr io.Writer, formatter string, data ...interface{}) {
+    for _, item := range data {
+        b, _ := item.([]byte)
+        s := string(b)
+        fmt.Fprintf(wr, strings.Replace(s, "\n", "<br/>", -1))
+    }
+}
+
 func init() {
     http.HandleFunc("/", func(w http.ResponseWriter, request *http.Request) {
         c := appengine.NewContext(request)
         fm := template.FormatterMap{}
         fm["date"] = dateFormatter
         fm["userName"] = userNameFormatter
+        fm["newlinesbr"] = newlineFormatter
         t, _ := template.ParseFile("templates/base.html", fm)
 
         current_user := user.Current(c)

templates/base.html

   <div>
     User: {AccountEmail|userName}<br/>
     {Date|date}
-    <p style="padding-left:10px">{Body|html}</p>
+    <p style="padding-left:10px">{Body|html|newlinesbr}</p>
   </div>
   {.end}