当前位置: 首页>>代码示例>>Golang>>正文


Golang github_flavored_markdown.Markdown函数代码示例

本文整理汇总了Golang中github.com/shurcooL/github_flavored_markdown.Markdown函数的典型用法代码示例。如果您正苦于以下问题:Golang Markdown函数的具体用法?Golang Markdown怎么用?Golang Markdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Markdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: todoHandler

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
}
开发者ID:WaNgeL-SaTaR,项目名称:paste-do,代码行数:26,代码来源:pastedo.go

示例2: getContentString

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
}
开发者ID:hhatto,项目名称:ftcat,代码行数:27,代码来源:main.go

示例3: GetTasks

//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
}
开发者ID:dot-Sean,项目名称:Tasks,代码行数:37,代码来源:tasks.go

示例4: GetComments

//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
}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:31,代码来源:tasks.go

示例5: renderFile

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
}
开发者ID:shaalx,项目名称:mdbgEg,代码行数:32,代码来源:main.go

示例6: SearchTask

//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
}
开发者ID:gotej,项目名称:Tasks,代码行数:28,代码来源:db.go

示例7: aboutPage

// 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)),
	})
}
开发者ID:edussx,项目名称:goblog,代码行数:12,代码来源:handler.go

示例8: MarkdownSource

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
	}
}
开发者ID:tobstarr,项目名称:tobstarr.com,代码行数:11,代码来源:sources.go

示例9: SanitisedBody

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))
}
开发者ID:solarnz,项目名称:starred-releases,代码行数:11,代码来源:feed.go

示例10: GetTasks

//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
}
开发者ID:devshell,项目名称:Tasks,代码行数:53,代码来源:tasks.go

示例11: WriteHtml

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()
}
开发者ID:parsnips,项目名称:snips,代码行数:14,代码来源:snips.go

示例12: SearchTask

//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
}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:49,代码来源:tasks.go

示例13:

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{})
}
开发者ID:joonazan,项目名称:go-opas,代码行数:48,代码来源:markdown.go

示例14: Markdown

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
}
开发者ID:everfore,项目名称:rpcsv,代码行数:19,代码来源:service.go

示例15: WriteIndex

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()
}
开发者ID:parsnips,项目名称:snips,代码行数:20,代码来源:snips.go


注:本文中的github.com/shurcooL/github_flavored_markdown.Markdown函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。