Switched from text/template to html/template

This commit is contained in:
Suraj Patil 2016-12-20 21:42:22 +05:30
parent f34db50464
commit eb45ec612e
6 changed files with 19 additions and 15 deletions

Binary file not shown.

View File

@ -9,6 +9,7 @@ DeleteAll()
import ( import (
"database/sql" "database/sql"
"html/template"
"log" "log"
"strconv" "strconv"
"strings" "strings"
@ -135,7 +136,7 @@ func GetTasks(username, status, category string) (types.Context, error) {
task.CompletedMsg = strconv.Itoa(taskCompleted) + " complete out of " + strconv.Itoa(totalTasks) task.CompletedMsg = strconv.Itoa(taskCompleted) + " complete out of " + strconv.Itoa(totalTasks)
} }
task.Content = string(md.Markdown([]byte(task.Content))) task.ContentHTML = template.HTML(md.Markdown([]byte(task.Content)))
// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1) // TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
if err != nil { if err != nil {
log.Println(err) log.Println(err)

View File

@ -59,7 +59,7 @@
</p> <span class="toggle glyphicon glyphicon-resize-full"></span> </p> <span class="toggle glyphicon glyphicon-resize-full"></span>
<span class="noteContent"> <span class="noteContent">
{{$value.Content}} {{$value.ContentHTML}}
{{$value.CompletedMsg}} {{$value.CompletedMsg}}
<div class="commentslist"> <div class="commentslist">
{{range $value.Comments}} {{range $value.Comments}}

View File

@ -1,22 +1,25 @@
package types package types
import "html/template"
/* /*
Package types is used to store the context struct which Package types is used to store the context struct which
is passed while templates are executed. is passed while templates are executed.
*/ */
//Task is the struct used to identify tasks //Task is the struct used to identify tasks
type Task struct { type Task struct {
Id int `json:"id"` Id int `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Created string `json:"created"` ContentHTML template.HTML `json:"content_html"`
Priority string `json:"priority"` Created string `json:"created"`
Category string `json:"category"` Priority string `json:"priority"`
Referer string `json:"referer,omitempty"` Category string `json:"category"`
Comments []Comment `json:"comments,omitempty"` Referer string `json:"referer,omitempty"`
IsOverdue bool `json:"isoverdue, omitempty"` Comments []Comment `json:"comments,omitempty"`
IsHidden int `json:"ishidden, omitempty` IsOverdue bool `json:"isoverdue, omitempty"`
CompletedMsg string `json:"ishidden, omitempty"` IsHidden int `json:"ishidden, omitempty`
CompletedMsg string `json:"ishidden, omitempty"`
} }
type Tasks []Task type Tasks []Task

View File

@ -5,13 +5,13 @@ Holds the non insert/update/delete related view handlers
*/ */
import ( import (
"html/template"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"text/template"
"github.com/thewhitetulip/Tasks/db" "github.com/thewhitetulip/Tasks/db"
"github.com/thewhitetulip/Tasks/sessions" "github.com/thewhitetulip/Tasks/sessions"

View File

@ -3,8 +3,8 @@ package views
/*Holds the fetch related view handlers*/ /*Holds the fetch related view handlers*/
import ( import (
"html/template"
"net/http" "net/http"
"text/template"
"time" "time"
"github.com/thewhitetulip/Tasks/db" "github.com/thewhitetulip/Tasks/db"