diff --git a/present/code.go b/present/code.go index 6fd9dade26..de15543109 100644 --- a/present/code.go +++ b/present/code.go @@ -32,6 +32,7 @@ type Code struct { Text template.HTML Play bool // runnable code Ext string // file extension + Raw []byte // content of the file } func (c Code) TemplateName() string { return "code" } @@ -130,6 +131,7 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele Text: template.HTML(buf.String()), Play: play, Ext: filepath.Ext(filename), + Raw: textBytes, }, nil } diff --git a/present/parse.go b/present/parse.go index a78a85b6ac..449d5ed5c9 100644 --- a/present/parse.go +++ b/present/parse.go @@ -41,6 +41,16 @@ func (d *Doc) Render(w io.Writer, t *template.Template) error { return t.ExecuteTemplate(w, "root", data) } +// Render renders the section to the given writer using the provided template. +func (s *Section) Render(w io.Writer, t *template.Template) error { + data := struct { + *Section + Template *template.Template + PlayEnabled bool + }{s, t, PlayEnabled} + return t.ExecuteTemplate(w, "section", data) +} + type ParseFunc func(ctx *Context, fileName string, lineNumber int, inputLine string) (Elem, error) // Register binds the named action, which does not begin with a period, to the