support for github flavoured markdown

This commit is contained in:
Suraj 2016-01-28 21:44:40 +05:30
parent 0a3231d369
commit df6d239ad3
3 changed files with 17 additions and 22 deletions

View File

@ -5,6 +5,7 @@ Tasks is a simplistic golang webapp to manage tasks, I built this tool to manage
Features: Features:
1. Add, update, delete note 1. Add, update, delete note
2. Search notes, the query is highlighted in the search results page 2. Search notes, the query is highlighted in the search results page
3. We use github flavoured markdown, which enables us for using a task list, advanced syntax highlighting and much more
How you install? How you install?
================== ==================
@ -12,7 +13,7 @@ How you install?
1. `go get github.com/thewhitetulip/Tasks` 1. `go get github.com/thewhitetulip/Tasks`
1. change dir to the respective folder and create the db file: `cat schema.sql | sqlite3 tasks.db` 1. change dir to the respective folder and create the db file: `cat schema.sql | sqlite3 tasks.db`
1. run `go build` 1. run `go build`
1. ./Task 1. `./Task`
1. open [localhost:8080](http://localhost:8080) 1. open [localhost:8080](http://localhost:8080)
Either this or download the latest from the release tab above and enjoy! Either this or download the latest from the release tab above and enjoy!

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
_ "github.com/mattn/go-sqlite3" //we want to use sqlite natively _ "github.com/mattn/go-sqlite3" //we want to use sqlite natively
"github.com/thewhitetulip/Tasks/types" "github.com/thewhitetulip/Tasks/types"
md "github.com/shurcooL/github_flavored_markdown"
"log" "log"
"strings" "strings"
"time" "time"
@ -52,7 +53,8 @@ func GetTasks(status string) types.Context {
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority) err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority)
TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1) TaskContent = string(md.Markdown([]byte(TaskContent)))
// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
@ -267,6 +269,7 @@ func SearchTask(query string) types.Context {
} }
TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1) TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1)
TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1) TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1)
TaskContent = string(md.Markdown([]byte(TaskContent)))
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]} a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
task = append(task, a) task = append(task, a)
} }

View File

@ -114,31 +114,28 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
file, handler, err := r.FormFile("uploadfile") file, handler, err := r.FormFile("uploadfile")
if err != nil { if err != nil {
log.Println(err) log.Println(err)
<<<<<<< HEAD
} }
taskPriority, priorityErr := strconv.Atoi(r.FormValue("priority")) taskPriority, priorityErr := strconv.Atoi(r.FormValue("priority"))
if priorityErr != nil { if priorityErr != nil {
log.Print("Someone trying to hack") log.Print(priorityErr)
} }
priorityList := []int{1, 2, 3} priorityList := []int{1, 2, 3}
found := false
for _, priority := range priorityList { for _, priority := range priorityList {
if taskPriority != priority { if taskPriority == priority {
log.Println("someone trying to hack") found = true
} }
} }
title := template.HTMLEscapeString(r.Form.Get("title")) //If someone gives us incorrect priority number, we give the priority
content := template.HTMLEscapeString(r.Form.Get("content")) //to that task as 1 i.e. Low
formToken := template.HTMLEscapeString(r.Form.Get("CSRFToken")) if found {
taskPriority = 1
=======
return
} }
title := template.HTMLEscapeString(r.Form.Get("title")) title := template.HTMLEscapeString(r.Form.Get("title"))
content := template.HTMLEscapeString(r.Form.Get("content")) content := template.HTMLEscapeString(r.Form.Get("content"))
formToken := template.HTMLEscapeString(r.Form.Get("CSRFToken")) formToken := template.HTMLEscapeString(r.Form.Get("CSRFToken"))
>>>>>>> 474ffbc0ea29e8ccacc707893a07534a4afed961
cookie, _ := r.Cookie("csrftoken") cookie, _ := r.Cookie("csrftoken")
if formToken == cookie.Value { if formToken == cookie.Value {
if handler != nil { if handler != nil {
@ -151,19 +148,13 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
} }
defer f.Close() defer f.Close()
io.Copy(f, file) io.Copy(f, file)
<<<<<<< HEAD
filelink := "<br> <a href=/files/" + handler.Filename + ">" + handler.Filename + "</a>" filelink := "<br> <a href=/files/" + handler.Filename + ">" + handler.Filename + "</a>"
content = content + filelink content = content + filelink
} }
truth := db.AddTask(title, content, taskPriority) truth := db.AddTask(title, content, taskPriority)
=======
filelink := "<br> <a href=./files/"+handler.Filename+">"+ handler.Filename+"</a>"
content = content + filelink
}
truth := db.AddTask(title, content)
>>>>>>> 474ffbc0ea29e8ccacc707893a07534a4afed961
if truth != nil { if truth != nil {
message = "Error adding task" message = "Error adding task"
log.Println("error adding task to db") log.Println("error adding task to db")