Exemplo n.º 1
0
func getFile(filename string) (string, os.Error) {
	if checkCache(filename) {
		b, err := ioutil.ReadFile("cache/" + filename + ".html")

		if err != nil {
			return "", err
		}

		fmt.Printf("Loaded cached file ``%s''\n", filename+".html")

		return string(b), nil
	}

	b, err := ioutil.ReadFile("pages/" + filename + ".md")
	if err != nil {
		return "", err
	}
	doc := md.Parse(string(b), md.Extensions{Smart: true})

	var buf bytes.Buffer
	doc.WriteHtml(&buf)

	html, err := Template(getLinks(), getProjects(), buf.String(), "page.html")
	if err != nil {
		return "", err
	}

	ioutil.WriteFile("cache/"+filename+".html", []byte(html), 0644)

	fmt.Printf("Parsed the file ``%s''\n", filename+".md")

	return html, nil
}
Exemplo n.º 2
0
func (n *NewsItem) FormattedFullDescription() string {

	doc := md.Parse(n.FullDescription, md.Extensions{Smart: true})

	buf := bytes.NewBuffer(nil)
	doc.WriteHtml(buf)

	return string(buf.Bytes())
}
Exemplo n.º 3
0
	// Load template which shows list of articles
	article_list := kview.New("list.kt")

	// Create main page
	main_view = layout.Copy()
	main_view.Div("left", article_list)
	main_view.Div("right", kview.New("show.kt", utils))

	// Create edit page
	edit_view = layout.Copy()
	edit_view.Div("left", article_list)
	edit_view.Div("right", kview.New("edit.kt"))
}

var (
	mde = markdown.Extensions{
		Smart:        true,
		Dlists:       true,
		FilterHTML:   true,
		FilterStyles: true,
	}
	utils = map[string]interface{}{
		"markdown": func(txt string) []byte {
			var buf bytes.Buffer
			doc := markdown.Parse(txt, mde)
			doc.WriteHtml(&buf)
			return buf.Bytes()
		},
	}
)