• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang markdown.ToHTML函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ReadmeHandler

func ReadmeHandler(res http.ResponseWriter, req *http.Request) {
	parser := markdown.NewParser(&markdown.Extensions{Smart: true})
	file, err := os.Open("README.md")
	if err != nil {
		fmt.Fprintln(res, err)
	} else {
		w := bufio.NewWriter(res)
		w.WriteString("<html>")
		w.WriteString(`<head><link href="http://kevinburke.bitbucket.org/markdowncss/markdown.css" rel="stylesheet"></link></head>`)
		w.WriteString(`<body><a href="https://github.com/janne/gometrics"><img style="position: absolute; top: 0; right: 30px; border: 0;" src="https://github.com/jamesflorentino/fork-ribbons/raw/master/ribbons/red-white.png" alt="Fork me on GitHub"></a>`)
		parser.Markdown(file, markdown.ToHTML(w))
		w.WriteString("</body></html>")
		w.Flush()
	}
}
开发者ID:janne,项目名称:gometrics,代码行数:15,代码来源:readme.go


示例17: Main

func Main() error {
	template, err := ioutil.ReadFile("template.html")
	if err != nil {
		return err
	}

	reader := bufio.NewReader(os.Stdin)

	var title string

	for {
		line, err := reader.ReadString('\n')
		if err != nil {
			return err
		}

		if strings.HasPrefix(line, "===") {
			break
		} else {
			title = line[:len(line)-1]
		}
	}

	md, err := ioutil.ReadAll(reader)
	if err != nil {
		return err
	}

	result := bytes.NewBuffer(nil)

	p := markdown.NewParser(nil)
	p.Markdown(bytes.NewReader(md), markdown.ToHTML(result))

	filtered, err := AfterFilter(result.Bytes())
	if err != nil {
		return err
	}

	template = bytes.Replace(template, []byte("{TITLE}"), []byte(title), -1)
	template = bytes.Replace(template, []byte("{CONTENT}"), filtered, -1)
	template = bytes.Replace(template, []byte("{NAME}"), []byte(os.Args[1]), -1)

	if _, err := os.Stdout.Write(template); err != nil {
		return err
	}

	return nil
}
开发者ID:rovaughn,项目名称:rovaughn.github.io,代码行数:48,代码来源:main.go


示例18: loadPage

// loadPage loads the markdown for a page from templates/title.markdown, and
// converts it to HTML, returning a new Page with
// Page.Title = title string
// Page.Body = new html
func loadPage(title string) (*Page, error) {
	// get markdown for page specified
	filename := "templates/" + title + ".markdown"
	markdown_file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer markdown_file.Close()

	// parse markdown into Page.Body
	var html_buf bytes.Buffer
	parser := markdown.NewParser(&markdown.Extensions{Smart: true})
	parser.Markdown(markdown_file, markdown.ToHTML(&html_buf))

	return &Page{Title: title, Body: html_buf.Bytes()}, nil
}
开发者ID:ramfjord,项目名称:goblog,代码行数:20,代码来源:wiki.go


示例19: retrieveContent

func (f *fetcher) retrieveContent(path string, extension string) (string, error) {
	u := dropbox.Uri{
		Root: "sandbox" + path,
	}

	file, _, err := dropbox.GetFile(f.Session, u, nil)
	if err != nil {
		return "", err
	}

	// Markdown check
	if extension == "md" {
		p := markdown.NewParser(&markdown.Extensions{Smart: true})
		buf := new(bytes.Buffer)
		p.Markdown(bytes.NewReader(file), markdown.ToHTML(buf))
		return buf.String(), nil
	} else {
		return string(file), nil
	}

}
开发者ID:pearkes,项目名称:sv-fetcher,代码行数:21,代码来源:fetcher.go


示例20: LoadPost

func LoadPost(post Post) (postData PostData) {
	// Read metadata
	metadata, err := ioutil.ReadFile(post.metadataPath)
	if err != nil {
		log.Fatal(err)
	}

	// Load params into a map
	var params map[string]interface{}
	err = json.Unmarshal(metadata, &params)
	if err != nil {
		log.Fatal(err)
	}

	// Read content file
	content, err := ioutil.ReadFile(post.contentPath)
	if err != nil {
		log.Fatal(err)
	}

	// Parse Markdown
	var b bytes.Buffer

	parser := markdown.NewParser(&markdown.Extensions{Smart: true})
	parser.Markdown(bytes.NewReader(content), markdown.ToHTML(&b))

	processedContent := b.String()

	// Populate postData
	postData.Title = params["title"].(string)
	postData.Date, err = time.Parse(time.RFC3339, params["date"].(string))
	postData.Params = params
	postData.Content = processedContent
	if err != nil {
		log.Fatal(err)
	}

	return
}
开发者ID:neunenak,项目名称:plume,代码行数:39,代码来源:post.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang internal.ArgType类代码示例发布时间:2022-05-23
下一篇:
Golang markdown.NewParser函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap