本文整理汇总了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()
}
示例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)
}
示例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()
}
示例4: GetWikiMarkup
func GetWikiMarkup(data []byte) []byte {
output := bytes.NewBuffer(nil)
reader := bytes.NewBuffer(data)
parser.Markdown(reader, markdown.ToHTML(output))
return output.Bytes()
}
示例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()
}
示例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()
}
示例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()
}
示例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()
}
示例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())
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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)
}
}
}
示例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
}