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


Golang blackfriday.MarkdownBasic函数代码示例

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


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

示例1: LoadRelated

func (a *Article) LoadRelated(s *mgo.Session) {
	fmt.Println("Meta start")
	if a.Meta == nil {
		a.Meta = make(map[string]interface{})
	}
	a.Meta["author"] = a.GetAuthor(s).String()
	a.Meta["markdown"] = template.HTML(string(blackfriday.MarkdownBasic([]byte(a.Body))))
	if len(a.Body) > trimLength {
		a.Meta["teaser"] = template.HTML(string(blackfriday.MarkdownBasic([]byte(a.Body[0:trimLength]))))
	} else {
		a.Meta["teaser"] = template.HTML(string(blackfriday.MarkdownBasic([]byte(a.Body[0:len(a.Body)]))))
	}
	fmt.Println("Meta:", a.Meta)

}
开发者ID:stunti,项目名称:bloggo,代码行数:15,代码来源:article.go

示例2: TestDocument

func TestDocument(t *testing.T) {
	const markdownIn = `This is Markdown.

- Item
- Item
- Item

And here are some ordered items.

1. Item 1
1. Item 2
1. Item 3

Cool.
`

	renderedHtml := blackfriday.MarkdownBasic([]byte(markdownIn))

	t.Log(string(renderedHtml))

	parsedHtml, err := html.Parse(bytes.NewReader(renderedHtml))
	if err != nil {
		panic(err)
	}

	markdownOut := html_to_markdown.Document(parsedHtml)

	if markdownIn != markdownOut {
		goon.DumpExpr(markdownIn, markdownOut)
		t.Fail()
	}
}
开发者ID:jmptrader,项目名称:go-1,代码行数:32,代码来源:main_test.go

示例3: BlogSaveHandler

func BlogSaveHandler(w http.ResponseWriter, r *http.Request, title string) {
	body := r.FormValue("body")

	const layout = "2006-01-02 15:04:05"
	t := time.Now()
	information := t.Format(layout)
	dBody := template.HTML(blackfriday.MarkdownBasic([]byte(html.EscapeString(body))))
	p := &Page{Title: title, DisplayBody: dBody, Information: information}
	versions := make(map[string]*Page)
	filename := "./blogs/" + p.Title
	file, err := os.Open(filename)
	if err == nil {
		defer file.Close()
		decoder := json.NewDecoder(file)
		decoder.Decode(&versions)

	}
	versions[t.Format(layout)] = p
	out, err := json.Marshal(versions)
	if err != nil {

	}

	ioutil.WriteFile(filename, out, 0600)
	http.Redirect(w, r, "/blog/"+title, http.StatusFound)
}
开发者ID:raygenbogen,项目名称:wiki,代码行数:26,代码来源:view.go

示例4: SaveHandler

func SaveHandler(w http.ResponseWriter, r *http.Request, title string) {
	body := r.FormValue("body")

	dBody := template.HTML(blackfriday.MarkdownBasic([]byte(html.EscapeString(body))))
	const layout = "2006-01-02 15:04:05"
	t := time.Now()
	cookie, err := r.Cookie("User")
	if err != nil {
		// just do something
	}
	author := cookie.Value
	information := "Aktualisiert:" + t.Format(layout) + " by " + string(author)
	p := &Page{Title: title, Body: body, DisplayBody: dBody, Information: information}
	versions := make(map[string]*Page)
	filename := "./articles/" + p.Title
	file, err := os.Open(filename)
	if err == nil {
		defer file.Close()
		decoder := json.NewDecoder(file)
		decoder.Decode(&versions)

	}
	versions[t.Format(layout)] = p
	out, err := json.Marshal(versions)
	if err != nil {
		fmt.Println("nicht jsoned")
	}

	ioutil.WriteFile(filename, out, 0600)
	http.Redirect(w, r, "/view/"+title, http.StatusFound)
}
开发者ID:raygenbogen,项目名称:wiki,代码行数:31,代码来源:view.go

示例5: main

func main() {
	setup()
	input := readInput(goopt.Args)
	if input == nil {
		fmt.Println("No input found")
		os.Exit(1)
	}
	outfile := getOutfile()
	markdown := blackfriday.MarkdownBasic(input)
	if *templatePath != "" {
		tpl, err := loadTemplate(*templatePath)
		if err != nil {
			fmt.Println("Template loading error: %v", err)
			os.Exit(2)
		}
		data := TemplateData{Contents: string(markdown)}
		err = tpl.Execute(outfile, data)
		if err != nil {
			fmt.Println("Template execution error: %v", err)
			os.Exit(3)
		}
		return
	}
	_, err := outfile.WriteString(string(markdown))
	if err != nil {
		fmt.Println("Write error: %v", err)
	}

	os.Exit(0)
}
开发者ID:manuclementz,项目名称:md,代码行数:30,代码来源:md.go

示例6: load

func (t *Template) load(g *Group, name string, info interface{}) error {
	t.g = g
	tmpl := template.New(name)
	tmpl.Funcs(g.Funcs)
	var fm map[string]interface{}
	bytes, err := fmatter.ReadFile(filepath.Join(g.Dir, name), &fm)
	if err != nil {
		return err
	}
	t.funcMap = template.FuncMap{
		"page": func() interface{} {
			return fm
		},
	}
	tmpl.Funcs(t.funcMap)
	ext := filepath.Ext(name)
	if ext == ".md" {
		bytes = blackfriday.MarkdownBasic(bytes)
	}
	_, err = tmpl.Parse(string(bytes))
	if err != nil {
		return err
	}
	t.tmpl = tmpl
	if l, ok := fm["layout"]; ok {
		t.layout = l.(string)
	} else {
		t.layout = "default"
	}
	//writeInfo(info, fm)
	return nil
}
开发者ID:james4k,项目名称:pages,代码行数:32,代码来源:template.go

示例7: PreViewArticleHandler

func PreViewArticleHandler(w http.ResponseWriter, r *http.Request) {
	ctx := GetContext()
	args := ctx.Args
	articleMetaData := &ArticleMetaData{}
	articleMetaData.Author, _ = args["author"].(string)
	articleMetaData.Title = strings.TrimSpace(r.FormValue("title"))
	tags := strings.TrimSpace(r.FormValue("tags"))
	if len(tags) > 0 {
		tags = strings.Replace(tags, ",", ",", -1)
		tags = strings.Replace(tags, " ", ",", -1)
		tag := strings.Split(tags, ",")
		articleMetaData.Tags = tag
	}
	articleMetaData.Summary = r.FormValue("summary")
	articleMetaData.Content = []byte(r.FormValue("content"))
	now := time.Now()
	articleMetaData.PostTime = now
	articleMetaData.UpdateTime = now
	articleMetaData.Flag = 1
	//article.Flag, _ = strconv.ParseInt(r.FormValue("flag"), 10, 64)
	articleMetaData.Count = 0

	article := &Article{MetaData: *articleMetaData,
		Text: template.HTML([]byte(blackfriday.MarkdownBasic(articleMetaData.Content)))}
	data := make(map[string]interface{})
	data["article"] = article

	args["title"] = articleMetaData.Title
	data["config"] = args
	viewTPL.ExecuteTemplate(w, "main", data)
}
开发者ID:wendyeq,项目名称:iweb-gae,代码行数:31,代码来源:iweb.go

示例8: main

func main() {

	rawKBZ, kbz := ScrapKBZ(kbz)
	rawCB, cb := ScrapCB(cb)

	r := gin.Default()

	r.GET("/:bank", func(c *gin.Context) {
		bankName := c.Params.ByName("bank")

		if bankName == "kbz" {
			bank := Process(rawKBZ, kbz)
			c.JSON(200, bank)
		} else if bankName == "cb" {
			bank := Process(rawCB, cb)
			c.JSON(200, bank)
		}
	})

	r.GET("/", func(c *gin.Context) {
		body, err := ioutil.ReadFile("README.md")
		PanicIf(err)
		c.String(200,
			string(blackfriday.MarkdownBasic([]byte(body))))
	})

	r.Run(":" + os.Getenv("PORT"))
}
开发者ID:mehulsbhatt,项目名称:banks,代码行数:28,代码来源:banks.go

示例9: EmailParticipants

func (t *Thing) EmailParticipants() error {
	if len(t.Participants) == 0 {
		return nil
	}

	showurl := fmt.Sprint(URL_ROOT, "/show/", t.Id)
	editurl := fmt.Sprint(URL_ROOT, "/edit/", t.Id)

	e := email.NewEmail()
	e.From = t.Owner.Email
	e.To = []string{}
	for _, p := range t.Participants {
		if !p.Done {
			e.To = append(e.To, p.Email)
		}
	}
	e.Subject = "A friendly reminder..."
	e.Text = []byte(fmt.Sprintf(texttempl, t.Owner.Email, showurl, t.ThingName, t.ThingLink, editurl))
	e.HTML = []byte(blackfriday.MarkdownBasic(e.Text))
	fmt.Printf("%v\n", e.To)
	println(string(e.Text))

	return e.Send("MAILHOST:25", nil)
	//	return nil

}
开发者ID:galaktor,项目名称:thingtracker,代码行数:26,代码来源:send.go

示例10: markdownComments

// Apply markdown to each section's documentation.
func markdownComments(sections []*section) {
	for _, section := range sections {
		// IMHO BlackFriday should use a string interface, since it
		// operates on text (not arbitrary binary) data...
		section.Doc = string(blackfriday.MarkdownBasic([]byte(section.Doc)))
	}
}
开发者ID:pgundlach,项目名称:docgo,代码行数:8,代码来源:doc.go

示例11: InflateSummary

// Fill in Summary and Body values from the Text byte slice.
func (this *Article) InflateSummary() {
	line := bytes.Index(this.Text, []byte("\r\n"))
	if line == -1 {
		line = len(this.Text)
	}
	this.Summary = string(blackfriday.MarkdownBasic(this.Text[:line]))
}
开发者ID:ricallinson,项目名称:juxsite,代码行数:8,代码来源:article.go

示例12: createPost

func createPost(file *os.File) (*Post, error) {
	post := &Post{}
	var err error = nil
	reader := bufio.NewReader(file)

	parse := func(prefix string) string {
		regex := regexp.MustCompile(prefix + ":")
		line, _ := reader.ReadString('\n')
		if match := regex.FindStringIndex(line); match != nil {
			return strings.TrimSpace(line[match[1] : len(line)-1])
		}
		err = fmt.Errorf("Expected %s string, got : \"%s\"", prefix, line)
		return ""
	}

	post.Title = parse("Title")
	date := parse("Date")
	post.Date, err = time.Parse("January 2, 2006", date)
	post.Filename = path.Base(file.Name())

	buffer := bytes.NewBuffer(nil)
	io.Copy(buffer, reader)
	post.Content = string(blackfriday.MarkdownBasic(buffer.Bytes()))

	return post, err
}
开发者ID:aaparella,项目名称:parellagram,代码行数:26,代码来源:post.go

示例13: FileAdd

func (this *TopicController) FileAdd() {
	this.Ctx.Request.ParseMultipartForm(32 << 20)
	file, _, err := this.Ctx.Request.FormFile("file")
	if err != nil {
		beego.Error("[上传文件错误]" + err.Error())
	}
	defer file.Close()
	datas, err := ioutil.ReadAll(file)
	fmt.Println("fmt", datas)
	if err != nil {
		beego.Error("[读取文件错误]" + err.Error())
	}

	beego.Info(string(datas) + "[datas]")

	a := string(datas)
	result := string(blackfriday.MarkdownBasic(datas))
	result = strings.Replace(result, "<code>", "<code class=\"go\">", -1)
	// this.Ctx.WriteString(string(datas)) 为什么这里不输出

	beego.Info(a)

	this.Data["json"] = result
	this.ServeJson()
}
开发者ID:xmvper,项目名称:golang-blog,代码行数:25,代码来源:topic.go

示例14: saveAllDir

func saveAllDir(db *mgo.Database, path string) {

	list, _ := ioutil.ReadDir(path)
	for _, f := range list {
		if f.IsDir() && strings.HasPrefix(f.Name(), "2014") {
			fmt.Println(f.Name())
			saveAllDir(db, filepath.Join(path, f.Name()))
		} else if strings.HasSuffix(f.Name(), ".md") && (strings.HasPrefix(f.Name(), "2015") || strings.HasPrefix(f.Name(), "2014")) {
			file, err := os.Open(filepath.Join(path, f.Name()))
			if err != nil {
				fmt.Println(err)
				return
			}
			defer file.Close()

			contents, err := ioutil.ReadAll(file)
			if err != nil {
				fmt.Println(err)
				return
			}

			unsafe := blackfriday.MarkdownBasic(contents)
			html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
			// fmt.Println(string(html))
			doc, err := goquery.NewDocumentFromReader(bytes.NewReader(html))
			langs := make(map[string]Repos)
			doc.Find("h4").Each(func(i int, hs *goquery.Selection) {
				var repos Repos

				hs.NextUntil("h4").Find("li").Each(func(i int, s *goquery.Selection) {
					repo := &Repo{}
					repo.URL, _ = s.Find("a").Attr("href")
					repo.Name = strings.Replace(strings.Replace(s.Find("a").Text(), " ", "", -1), "\n", "", -1)
					// repo.Description =
					parts := strings.Split(s.Text(), ":")
					repo.Description = strings.TrimSpace(strings.Replace(strings.Join(parts[1:], ""), "\n", "", -1))

					img, ok := s.Find("img").Attr("src")
					if ok {
						repo.BuiltBy = Contributors{Contributor{
							Avatar: img,
							// Username: "$$unknown$$",
						}}
					}
					repos = append(repos, repo)
				})
				fmt.Println("len:", len(repos))
				langs[strings.Title(hs.Text())] = repos
			})
			_, filename := filepath.Split(file.Name())
			ymd := strings.Split(strings.TrimSuffix(filename, ".md"), "-")
			s := &Snapshot{
				Date:      fmt.Sprintf("%s-%s-%s", ymd[2], ymd[1], ymd[0]),
				Languages: langs,
			}
			s.Save(db)
		}
	}
}
开发者ID:celrenheit,项目名称:trending-machine,代码行数:59,代码来源:hubspider_test.go

示例15: main

func main() {
	m := martini.Classic()
	m.Post("/generate", func(r *http.Request) []byte {
		body := r.FormValue("body")
		return blackfriday.MarkdownBasic([]byte(body))
	})
	m.Run()
}
开发者ID:jboursiquot,项目名称:markdown-parser,代码行数:8,代码来源:main.go


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