當前位置: 首頁>>代碼示例>>Golang>>正文


Golang markdown.NewParser函數代碼示例

本文整理匯總了Golang中github.com/knieriem/markdown.NewParser函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewParser函數的具體用法?Golang NewParser怎麽用?Golang NewParser使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewParser函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例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: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的github.com/knieriem/markdown.NewParser函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。