示例#1
0
func todoHandler(storage Storage) http.HandlerFunc {
	fn := func(w http.ResponseWriter, r *http.Request) {
		tmpl, _ := template.ParseFiles("templates/todo.html")
		id := r.URL.Path[len("/todo/"):]
		val := storage.Get(id)
		markdown := string(github_flavored_markdown.Markdown(([]byte)(val.Content)))

		out := struct {
			ID              string
			Content         string
			Visits          uint64
			CreatedAt       time.Time
			UpdatedAt       time.Time
			MarkdownContent template.HTML
		}{
			id,
			(*val).Content,
			(*val).Visits,
			(*val).CreatedAt,
			(*val).UpdatedAt,
			template.HTML(markdown),
		}
		tmpl.Execute(w, out)
	}
	return fn
}
示例#2
0
文件: main.go 项目: hhatto/ftcat
func getContentString(filename string) (output string, err error) {
	ext := filepath.Ext(filename)
	if ext == ".md" {
		var input []byte
		if input, err = ioutil.ReadFile(targetFileName); err != nil {
			log.Println("indexHandler: ", err)
			return "", err
		}
		o := github_flavored_markdown.Markdown(input)
		outputBuffer := bytes.NewBuffer(o)
		output = outputBuffer.String()
	} else {
		// rst
		input, err := os.Open(filename)
		if err != nil {
			log.Printf("%v", err)
			return "", err
		}
		defer input.Close()
		var buf bytes.Buffer
		p := rst.NewParser(nil)
		html := rst.ToHTML(&buf)
		p.ReStructuredText(input, html)
		output = buf.String()
	}
	return output, err
}
示例#3
0
文件: tasks.go 项目: dot-Sean/Tasks
//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status string) (types.Context, error) {
	var task []types.Task
	var context types.Context
	var TaskID int
	var TaskTitle string
	var TaskContent string
	var TaskCreated time.Time
	var TaskPriority string
	var getTasksql string

	basicSQL := "select id, title, content, created_date, priority from task "
	if status == "pending" {
		getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
	} else if status == "deleted" {
		getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc"
	} else if status == "completed" {
		getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc"
	}

	rows := database.query(getTasksql)
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority)
		TaskContent = string(md.Markdown([]byte(TaskContent)))
		// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			log.Println(err)
		}
		TaskCreated = TaskCreated.Local()
		a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20], Priority: TaskPriority}
		task = append(task, a)
	}
	context = types.Context{Tasks: task, Navigation: status}
	return context, nil
}
示例#4
0
//GetComments is used to get comments, all of them.
//We do not want 100 different pages to show tasks, we want to use as few pages as possible
//so we are going to populate everything on the damn home pages
func GetComments(username string) (map[int][]types.Comment, error) {
	commentMap := make(map[int][]types.Comment)

	var taskID int
	var comment types.Comment
	var created time.Time

	userID, err := GetUserID(username)
	if err != nil {
		return commentMap, err
	}
	stmt := "select c.id, c.taskID, c.content, c.created, u.username from comments c, task t, user u where t.id=c.taskID and c.user_id=t.user_id and t.user_id=u.id and u.id=?"
	rows := database.query(stmt, userID)

	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created, &comment.Username)
		comment.Content = string(md.Markdown([]byte(comment.Content)))
		if err != nil {
			return commentMap, err
		}
		// comment.Content = string(md.Markdown([]byte(comment.Content))) ## have to fix the <p> issue markdown support
		created = created.Local()
		comment.Created = created.Format("Jan 2 2006 15:04:05")
		commentMap[taskID] = append(commentMap[taskID], comment)
	}
	return commentMap, nil
}
示例#5
0
文件: main.go 项目: shaalx/mdbgEg
func renderFile(filename string, redo bool) bool {
	_, err := os.Lstat(filename + ".html")
	if !redo && nil == err {
		return false
	}
	if nil == err {
		err = os.Remove(filename + ".html")
		goutils.CheckErr(err)
	}
	input := readFile(filename)
	if nil == input {
		return false
	}
	// unsafe := blackfriday.MarkdownCommon(input)
	// html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
	html := md.Markdown(input)

	data := make(map[string]interface{})
	data["MDContent"] = goutils.ToString(html)

	data["Title"] = getName(filename)
	of, err := os.OpenFile( /*targetDir+string(os.PathSeparator)+*/ filename+".html", os.O_CREATE|os.O_RDWR, 0666)
	defer of.Close()
	if goutils.CheckErr(err) {
		return false
	}
	err = theme.Execute(of, data)
	if goutils.CheckErr(err) {
		return false
	}
	return true
}
示例#6
0
文件: db.go 项目: gotej/Tasks
//SearchTask is used to return the search results depending on the query
func SearchTask(query string) types.Context {
	stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'"
	var task []types.Task
	var TaskID int
	var TaskTitle string
	var TaskContent string
	var TaskCreated time.Time
	var context types.Context

	rows, err := database.Query(stmt, query, query)
	if err != nil {
		log.Println(err)
	}
	for rows.Next() {
		err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
		if err != nil {
			log.Println(err)
		}
		TaskTitle = strings.Replace(TaskTitle, 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]}
		task = append(task, a)
	}
	context = types.Context{Tasks: task, Search: query}
	return context
}
示例#7
0
文件: handler.go 项目: edussx/goblog
// Todo
// Load config instead (e.g. blog name, author, etc.)
func aboutPage(c *gin.Context) {
	md, err := ioutil.ReadFile(AboutPagePath)
	if err != nil {
		c.String(http.StatusNotFound, "Not Found\n")
	}
	output := github_flavored_markdown.Markdown(md)
	c.HTML(http.StatusOK, "page.tmpl", gin.H{
		"body": template.HTML(string(output)),
	})
}
示例#8
0
func MarkdownSource(in Source) Source {
	return func(w io.Writer) error {
		buf := &bytes.Buffer{}
		if err := in(buf); err != nil {
			return err
		}
		b := github_flavored_markdown.Markdown(buf.Bytes())
		_, err := w.Write(b)
		return err
	}
}
示例#9
0
func (r Release) SanitisedBody() string {
	var i string
	if r.Body == nil {
		i = ""
	} else {
		i = *r.Body
	}
	s := bluemonday.UGCPolicy()
	b := md.Markdown([]byte(i))
	return string(s.SanitizeBytes(b))
}
示例#10
0
文件: tasks.go 项目: devshell/Tasks
//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status, category string) (types.Context, error) {
	var tasks []types.Task
	var task types.Task
	var TaskCreated time.Time
	var context types.Context
	var getTasksql string
	var rows *sql.Rows

	comments := GetComments()

	basicSQL := "select id, title, content, created_date, priority from task t"
	if status == "pending" && category == "" {
		getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
	} else if status == "deleted" {
		getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc"
	} else if status == "completed" {
		getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc"
	}

	if category != "" {
		status = category
		getTasksql = "select t.id, title, content, created_date, priority from task t, category c where c.id = t.cat_id and name = ?  and  t.is_deleted!='Y' and t.finish_date is null  order by priority desc, created_date asc, finish_date asc"
		rows, err = database.db.Query(getTasksql, category)
		if err != nil {
			log.Println("something went wrong while getting query")
		}
	} else {
		rows = database.query(getTasksql)
	}
	defer rows.Close()
	for rows.Next() {
		task = types.Task{}
		err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority)
		task.Content = string(md.Markdown([]byte(task.Content)))
		// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			log.Println(err)
		}

		if comments[task.Id] != nil {
			task.Comments = comments[task.Id]
		}

		TaskCreated = TaskCreated.Local()
		task.Created = TaskCreated.Format(time.UnixDate)[0:20]

		tasks = append(tasks, task)
	}
	context = types.Context{Tasks: tasks, Navigation: status}
	return context, nil
}
示例#11
0
文件: snips.go 项目: parsnips/snips
func WriteHtml(markdown []byte, filePath string) {
	output := github_flavored_markdown.Markdown(markdown)
	f, err := os.Create(filePath)
	check(err)

	defer wg.Done()
	defer f.Close()

	WriteHeader(f)
	_, err = f.Write(output)
	check(err)

	f.Sync()
}
示例#12
0
//SearchTask is used to return the search results depending on the query
func SearchTask(username, query string) (types.Context, error) {
	var tasks []types.Task
	var task types.Task
	var TaskCreated time.Time
	var context types.Context

	comments, err := GetComments(username)
	if err != nil {
		log.Println("SearchTask: something went wrong in finding comments")
	}

	userID, err := GetUserID(username)
	if err != nil {
		return context, err
	}

	stmt := "select t.id, title, content, created_date, priority, c.name from task t, category c where t.user_id=? and c.id = t.cat_id and (title like '%" + query + "%' or content like '%" + query + "%') order by created_date desc"

	rows := database.query(stmt, userID, query, query)
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category)
		if err != nil {
			log.Println(err)
		}

		if comments[task.Id] != nil {
			task.Comments = comments[task.Id]
		}

		task.Title = strings.Replace(task.Title, query, "<span class='highlight'>"+query+"</span>", -1)
		task.Content = strings.Replace(task.Content, query, "<span class='highlight'>"+query+"</span>", -1)
		task.Content = string(md.Markdown([]byte(task.Content)))

		TaskCreated = TaskCreated.Local()
		CurrentTime := time.Now().Local()
		week := TaskCreated.AddDate(0, 0, 7)

		if (week.String() < CurrentTime.String()) && (task.Priority != "1") {
			task.IsOverdue = true // If one week then overdue by default
		}
		task.Created = TaskCreated.Format("Jan 2 2006")

		tasks = append(tasks, task)
	}
	context = types.Context{Tasks: tasks, Search: query, Navigation: "search"}
	return context, nil
}
示例#13
0
func rinnastuksetHTMLläksi(md []byte) []byte {
	var (
		alku  = []byte("??rinnan")
		väli  = []byte("??v")
		loppu = []byte("??l")
	)

	palat := make([][]byte, 0)

	for {
		alkupaikka := bytes.Index(md, alku)
		if alkupaikka == -1 {
			break
		}

		palat = append(palat,
			md[:alkupaikka],
			[]byte("<div class=comparison><div class=compcell>"),
		)

		md = md[alkupaikka+len(alku):]

		loppupaikka := bytes.Index(md, loppu)

		for seuraava := bytes.Index(md, väli); seuraava != -1 && seuraava < loppupaikka; seuraava = bytes.Index(md, väli) {
			palat = append(palat,
				md[:seuraava],
				[]byte("</div><div class=compcell>"),
			)
			uusiAlku := seuraava + len(väli)
			md = md[uusiAlku:]
			loppupaikka -= uusiAlku
		}
		palat = append(palat,
			md[:loppupaikka],
			[]byte("</div></div>"),
		)
		md = md[loppupaikka+len(loppu):]
	}

	palat = append(palat, md)

	for i := range palat {
		palat[i] = gfm.Markdown(lisääKoodi(palat[i]))
	}

	return bytes.Join(palat, []byte{})
}
示例#14
0
文件: service.go 项目: everfore/rpcsv
func (r *RPC) Markdown(in, out *([]byte)) error {
	// fmt.Println(goutils.ToString(*in))
	html := md.Markdown(*in)
	*out = html

	// goutils.ReWriteFile("tempory.tmp", nil)
	// of, _ := os.OpenFile("tempory.tmp", os.O_CREATE|os.O_WRONLY, 0666)
	// defer of.Close()
	// data := make(map[string]interface{})
	// data["MDContent"] = template.HTML(goutils.ToString(html))
	// err := Theme.Execute(of, data)
	// if goutils.CheckErr(err) {
	// 	return err
	// }
	// *out = goutils.ReadFile("tempory.tmp")
	// fmt.Println(goutils.ToString(html))
	// fmt.Println("out:", goutils.ToString(*out))
	return nil
}
示例#15
0
文件: snips.go 项目: parsnips/snips
func WriteIndex(links []string, outputDir string) {
	idx := make([]byte, 0)
	title := []byte("Parsnips.net\n-----------------\n")

	idx = append(idx, title...)

	for _, link := range links {
		idx = append(idx, []byte(link)...)
	}

	f, err := os.Create(outputDir + "/index.html")
	check(err)

	defer f.Close()
	WriteHeader(f)
	_, err = f.Write(github_flavored_markdown.Markdown(idx))
	check(err)
	WriteTrailer(f)
	f.Sync()
}
示例#16
0
文件: api.go 项目: sguzwf/go-wiki
func DiffHandler(w http.ResponseWriter, r *http.Request) {
	parts := strings.Split(r.URL.Path[len("/api/diff/"):], "/")
	if len(parts) != 2 {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
	}

	hash := parts[0]
	file := parts[1] + ".md"

	diff, err := Diff(file, hash)
	if err != nil {
		log.Println("ERROR", "Failed to get commit hash", hash)
	}

	// XXX: This could probably be done in a nicer way
	wrappedDiff := []byte("```diff\n" + string(diff) + "```")
	// md := blackfriday.MarkdownCommon(wrappedDiff)
	md := github_flavored_markdown.Markdown(wrappedDiff)

	w.Header().Set("Content-Type", "text/html")
	w.Write(md)
}
示例#17
0
文件: main.go 项目: rexposadas/gx
// WriteGitHubFlavoredMarkdownViaLocal converts GitHub Flavored Markdown to full HTML page and writes it to w.
func WriteGitHubFlavoredMarkdownViaLocal(w io.Writer, markdown []byte) {
	io.WriteString(w, `<html><head><meta charset="utf-8"><link href="https://dl.dropboxusercontent.com/u/8554242/temp/github-flavored-markdown.css" media="all" rel="stylesheet" type="text/css" /><link href="//cdnjs.cloudflare.com/ajax/libs/octicons/2.1.2/octicons.css" media="all" rel="stylesheet" type="text/css" /></head><body><article class="markdown-body entry-content" style="padding: 30px;">`)
	w.Write(github_flavored_markdown.Markdown(markdown))
	io.WriteString(w, `</article></body></html>`)
}
示例#18
0
文件: markdown.go 项目: kamito/c3h8
func (self Markdown) ToHtml(input []byte) string {
	output := github_flavored_markdown.Markdown(input)
	return string(output)
}
//export gfm
func gfm(text *C.char) *C.char {
	mdString := C.GoString(text)
	result := github_flavored_markdown.Markdown([]byte(mdString))
	return C.CString(string(result))
}
示例#20
0
//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(username, status, category string) (types.Context, error) {
	log.Println("getting tasks for ", status)
	var tasks []types.Task
	var task types.Task
	var TaskCreated time.Time
	var context types.Context
	var getTaskSQL string
	var rows *sql.Rows

	comments, err := GetComments(username)

	if err != nil {
		return context, err
	}

	basicSQL := "select t.id, title, content, created_date, priority, case when c.name is null then 'NA' else c.name end from task t, status s, user u left outer join  category c on c.id=t.cat_id where u.username=? and s.id=t.task_status_id and u.id=t.user_id "
	if category == "" {
		switch status {
		case "pending":
			getTaskSQL = basicSQL + " and s.status='PENDING' and t.hide!=1"
		case "deleted":
			getTaskSQL = basicSQL + " and s.status='DELETED' and t.hide!=1"
		case "completed":
			getTaskSQL = basicSQL + " and s.status='COMPLETE' and t.hide!=1"
		}

		getTaskSQL += " order by t.created_date asc"

		rows = database.query(getTaskSQL, username, username)
	} else {
		status = category
		//This is a special case for showing tasks with null categories, we do a union query
		if category == "UNCATEGORIZED" {
			getTaskSQL = "select t.id, title, content, created_date, priority, 'UNCATEGORIZED' from task t, status s, user u where u.username=? and s.id=t.task_status_id and u.id=t.user_id and t.cat_id=0  and  s.status='PENDING'  order by priority desc, created_date asc, finish_date asc"
			rows, err = database.db.Query(getTaskSQL, username)
		} else {
			getTaskSQL = basicSQL + " and name = ?  and  s.status='PENDING'  order by priority desc, created_date asc, finish_date asc"
			rows, err = database.db.Query(getTaskSQL, username, category)
		}

		if err != nil {
			log.Println("tasks.go: something went wrong while getting query fetch tasks by category")
		}
	}

	defer rows.Close()
	for rows.Next() {
		task = types.Task{}

		err = rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category)

		taskCompleted := 0
		totalTasks := 0

		if strings.HasPrefix(task.Content, "- [") {
			for _, value := range strings.Split(task.Content, "\n") {
				if strings.HasPrefix(value, "- [x]") {
					taskCompleted += 1
				}
				totalTasks += 1
			}
			task.CompletedMsg = strconv.Itoa(taskCompleted) + " complete out of " + strconv.Itoa(totalTasks)
		}

		task.ContentHTML = template.HTML(md.Markdown([]byte(task.Content)))
		// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
		if err != nil {
			log.Println(err)
		}

		if comments[task.Id] != nil {
			task.Comments = comments[task.Id]
		}

		TaskCreated = TaskCreated.Local()
		// if task.Priority != "1" { // if priority is not 1 then calculate, else why bother?
		// CurrentTime := time.Now().Local()
		// diff := CurrentTime.Sub(TaskCreated).Hours()
		// if diff > 168 {
		// 	task.IsOverdue = true // If one week then overdue by default
		// }
		// }
		task.Created = TaskCreated.Format("Jan 2 2006")

		tasks = append(tasks, task)
	}
	context = types.Context{Tasks: tasks, Navigation: status}
	return context, nil
}
示例#21
0
func markDowner(args ...interface{}) string {
	return string(github_flavored_markdown.Markdown([]byte(fmt.Sprintf("%s", args...))))
}
示例#22
0
文件: gowiki.go 项目: gale320/gowiki
// renders a page and sets its Rendered content
func (p *Page) Render() string {
	b := github_flavored_markdown.Markdown([]byte(p.Content))
	p.Rendered = string(b)
	p.Rendered, p.Links = MediaWikiParse(p.Rendered)
	return p.Rendered
}