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


Golang markdown.ToHTML函数代码示例

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


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

示例1: MakeSummary

func MakeSummary(post Mapper, lines int, topCtx mustache.Context) string {
	content := post["_content"].(*DocContent).Source
	r := bufio.NewReader(bytes.NewBufferString(content))
	dst := ""
	for lines > 0 {
		line, _ := r.ReadString('\n')
		dst += line
		lines--
		if lines == 0 {
			for "" != strings.Trim(line, "\r\n\t ") {
				line, _ = r.ReadString('\n')
				dst += line
			}
		}
	}
	str, err := mustache.RenderString(dst, topCtx)
	if err != nil {
		log.Println("BAD Mustache after Summary cut!")
		str, err = mustache.RenderString(dst, topCtx)
		if err != nil {
			log.Println("BAD Mustache Summary?", err)
			str = post["_content"].(*DocContent).Main
		}
	}
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	buf := bytes.NewBuffer(nil)
	mdParser.Markdown(bytes.NewBufferString(str), markdown.ToHTML(buf))
	return buf.String()
}
开发者ID:yemaocheng,项目名称:gor,代码行数:29,代码来源:compile.go

示例2: saveHandler

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

	// save markdown source
	p := &page.Page{Title: title, Body: []byte(body)}
	err := page.Save(pageSrcLocation, p)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// save html
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	mdBody := bytes.NewBuffer(nil)

	mdParser.Markdown(strings.NewReader(body), markdown.ToHTML(mdBody))
	p = &page.Page{Title: title, Body: []byte(mdBody.String())}
	err = page.Save(pageLocation, p)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	http.Redirect(w, r, "/view/"+title, http.StatusFound)
}
开发者ID:KaeruCT,项目名称:go-learn,代码行数:25,代码来源:wiki.go

示例3: main

func main() {
	var opt markdown.Extensions
	flag.BoolVar(&opt.Notes, "notes", false, "turn on footnote syntax")
	flag.BoolVar(&opt.Smart, "smart", false, "turn on smart quotes, dashes, and ellipses")
	flag.BoolVar(&opt.Dlists, "dlists", false, "support definitions lists")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [FILE]\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()

	r := os.Stdin
	if flag.NArg() > 0 {
		f, err := os.Open(flag.Arg(0))
		if err != nil {
			log.Fatal(err)
		}
		defer f.Close()
		r = f
	}

	p := markdown.NewParser(&opt)

	startPProf()
	defer stopPProf()

	w := bufio.NewWriter(os.Stdout)
	p.Markdown(r, markdown.ToHTML(w))
	w.Flush()
}
开发者ID:nuance,项目名称:markdown,代码行数:31,代码来源:main.go

示例4: GetWikiMarkup

func GetWikiMarkup(data []byte) []byte {
	output := bytes.NewBuffer(nil)
	reader := bytes.NewBuffer(data)

	parser.Markdown(reader, markdown.ToHTML(output))
	return output.Bytes()
}
开发者ID:jamra,项目名称:gowiki,代码行数:7,代码来源:wiki.go

示例5: markdownToHtml

func (wc *webConverter) markdownToHtml(content string) string {
	var mparser = markdown.NewParser(nil)
	stringBuffer := strings.NewReader(content)
	bufferReader := new(bytes.Buffer)
	mparser.Markdown(stringBuffer, markdown.ToHTML(bufferReader))
	return bufferReader.String()
}
开发者ID:Jormundir,项目名称:builder,代码行数:7,代码来源:converter.go

示例6: markdownFormat

func markdownFormat(text string) string {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})
	// w := bufio.NewWriter(os.Stdout)
	buffer := bytes.NewBufferString("")
	p.Markdown(strings.NewReader(text), markdown.ToHTML(buffer))
	return buffer.String()
}
开发者ID:Encinarus,项目名称:lightpegasus.com,代码行数:7,代码来源:main.go

示例7: RenderMarkdown

func RenderMarkdown(md string) string {
	htmlbuf := bytes.NewBufferString("")
	p := markdown.NewParser(&markdown.Extensions{Smart: true, FilterHTML: false})
	w := bufio.NewWriter(htmlbuf)
	p.Markdown(bytes.NewBufferString(md), markdown.ToHTML(w))
	w.Flush()
	return htmlbuf.String()
}
开发者ID:jojun,项目名称:golang-slides,代码行数:8,代码来源:render.go

示例8: fromMarkdown

func fromMarkdown(src string) string {
	// Dance for the markdown library:
	body := []byte(src)
	bodyReader := bytes.NewReader(body)
	markup := new(bytes.Buffer)
	p := markdown.NewParser(&markdown.Extensions{Smart: true, Notes: true})
	p.Markdown(bodyReader, markdown.ToHTML(markup))
	return markup.String()
}
开发者ID:redneckbeard,项目名称:penny,代码行数:9,代码来源:page.go

示例9: tmplMarkdown

// tmplMarkdown formats a given string using markdown
func tmplMarkdown(t string) template.HTML {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})

	inbuf := bytes.NewBufferString(t)
	outbuf := bytes.NewBufferString("")
	p.Markdown(inbuf, markdown.ToHTML(outbuf))

	return template.HTML(outbuf.String())
}
开发者ID:FliPPeh,项目名称:goblog,代码行数:10,代码来源:blogserver.go

示例10: Markdown2html

// 把Markdown文本转换为HTML
func Markdown2html(strMarkdown string) (html string) {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})
	var buf bytes.Buffer
	w := bufio.NewWriter(&buf)
	r := bytes.NewBufferString(strMarkdown)
	p.Markdown(r, markdown.ToHTML(w))
	w.Flush()
	html = string(buf.Bytes())
	return
}
开发者ID:JessonChan,项目名称:seocms,代码行数:11,代码来源:tools.go

示例11: filter

func (*mdFilter) filter(input []byte) bytes.Buffer {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})
	var buf bytes.Buffer
	buf.WriteString(`<html><header><style type="text/css">`)
	buf.WriteString(CSS)
	buf.WriteString("</style></header><body>")
	p.Markdown(bytes.NewReader(input), markdown.ToHTML(&buf))
	buf.WriteString("</body></html>")
	return buf
}
开发者ID:shitfSign,项目名称:gohttpd,代码行数:10,代码来源:filters.go

示例12: MarkdownToHtml

func MarkdownToHtml(content string) (str string) {
	defer func() {
		e := recover()
		if e != nil {
			log.Println(e)
		}
	}()
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	buf := bytes.NewBuffer(nil)
	mdParser.Markdown(bytes.NewBufferString(content), markdown.ToHTML(buf))
	str = buf.String()
	return
}
开发者ID:xushiwei,项目名称:gor,代码行数:13,代码来源:markdown.go

示例13: main

func main() {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})

	file, _ := os.Open("test.md")
	outfile, _ := os.Create("test_out.html")
	defer file.Close()
	defer outfile.Close()

	in := bufio.NewReader(file)
	out := bufio.NewWriter(outfile)
	p.Markdown(in, markdown.ToHTML(out))
	out.Flush()
}
开发者ID:itang,项目名称:_my,代码行数:13,代码来源:main.go

示例14: toHTML

// converts posts's BodyMarkdown to HTML (BodyHTML) if post does not already have HTML
func toHTML(posts []*Post) {
	parser := markdown.NewParser(&markdown.Extensions{Smart: true})
	for _, post := range posts {
		if post.BodyHTML == "" {
			log.Printf("\"%s\": Converting Markdown to HTML\n", post.Slug)
			html := new(bytes.Buffer)
			parser.Markdown(strings.NewReader(post.BodyMarkdown), markdown.ToHTML(html))
			post.BodyHTML = html.String()
		} else {
			log.Printf("\"%s\": HTML already exists, not using Markdown\n", post.Slug)
		}
	}
}
开发者ID:visualmotive,项目名称:gobig,代码行数:14,代码来源:gobig.go

示例15: PrapreMainContent

func PrapreMainContent(id string, content string, ctx mustache.Context) (string, error) {
	mdParser := markdown.NewParser(&markdown.Extensions{Smart: true})
	str, err := mustache.RenderString(content, ctx)
	if err != nil {
		return str, err
	}
	if strings.HasSuffix(id, ".md") || strings.HasSuffix(id, ".markdown") {
		//log.Println("R: MD : " + id)
		buf := bytes.NewBuffer(nil)
		mdParser.Markdown(bytes.NewBufferString(str), markdown.ToHTML(buf))
		str = buf.String()
	}
	return str, nil
}
开发者ID:yemaocheng,项目名称:gor,代码行数:14,代码来源:compile.go


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