本文整理汇总了Golang中github.com/shurcooL/github_flavored_markdown.Markdown函数的典型用法代码示例。如果您正苦于以下问题:Golang Markdown函数的具体用法?Golang Markdown怎么用?Golang Markdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Markdown函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: DiffHandler
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)
}
开发者ID:sguzwf,项目名称:go-wiki,代码行数:22,代码来源:api.go
示例17: WriteGitHubFlavoredMarkdownViaLocal
// 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>`)
}
开发者ID:rexposadas,项目名称:gx,代码行数:6,代码来源:main.go
示例18: ToHtml
func (self Markdown) ToHtml(input []byte) string {
output := github_flavored_markdown.Markdown(input)
return string(output)
}
开发者ID:kamito,项目名称:c3h8,代码行数:4,代码来源:markdown.go
示例19: gfm
//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))
}
开发者ID:tka,项目名称:rubyconf-tw-2015-ruby-go,代码行数:6,代码来源:libgo_example_gfm.go
示例20: GetTasks
//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
}
开发者ID:thewhitetulip,项目名称:Tasks,代码行数:91,代码来源:tasks.go
注:本文中的github.com/shurcooL/github_flavored_markdown.Markdown函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论