本文整理汇总了Golang中github.com/wendal/mustache.RenderString函数的典型用法代码示例。如果您正苦于以下问题:Golang RenderString函数的具体用法?Golang RenderString怎么用?Golang RenderString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RenderString函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
}
return MarkdownToHtml(str)
}
示例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()
}
示例3: 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)
str = MarkdownToHtml(str)
}
return str, nil
}
示例4: PrapreMainContent
func PrapreMainContent(id string, content string, ctx mustache.Context) (string, error) {
str, err := mustache.RenderString(content, ctx)
if err != nil {
Log(INFO, "Error when parse %s", id)
return str, err
}
if strings.HasSuffix(id, ".md") || strings.HasSuffix(id, ".markdown") {
Log(DEBUG, "Read markdown: %s", id)
str = MarkdownToHtml(str)
}
return str, nil
}
示例5: MakeSummary
func MakeSummary(post Mapper, lines int, topCtx mustache.Context) string {
content := post["_content"].(*DocContent).Source
r := bufio.NewReader(bytes.NewBufferString(content))
dst := ""
readUntil := ""
for lines > 0 {
line, _ := r.ReadString('\n')
dst += line
lines--
if strings.Trim(line, "\r\n\t ") == "```" {
if readUntil == "" {
readUntil = "```"
} else {
readUntil = ""
}
}
if lines == 0 {
var err error
for readUntil != strings.Trim(line, "\r\n\t ") {
line, err = r.ReadString('\n')
dst += line
if err != nil {
break
}
}
}
}
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
}
}
str = strings.Replace(str, TOC_MARKUP, "", 1)
return MarkdownToHtml(str)
}
示例6: 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
}
示例7: RenderInLayout
func RenderInLayout(content string, layoutName string, layouts map[string]Mapper, ctx mustache.Context) (string, error) {
//log.Println("Render Layout", layoutName, ">>", content, "<<END")
ctx2 := make(map[string]string)
ctx2["content"] = content
layout := layouts[layoutName]
str, err := mustache.RenderString(layout["_content"].(*DocContent).Source, ctx2, ctx)
if err != nil {
return content, err
}
if layout.Layout() != "" {
return RenderInLayout(str, layout.Layout(), layouts, ctx)
}
return str, nil
}