Ejemplo n.º 1
0
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)
}
Ejemplo n.º 2
0
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()
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
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
}
Ejemplo n.º 5
0
Archivo: compile.go Proyecto: 29n/gor
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)
}
Ejemplo n.º 6
0
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
}
Ejemplo n.º 7
0
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
}