mirror of
https://github.com/lancatlin/mdsh.git
synced 2026-11-05 19:30:12 +08:00
24 lines
385 B
Go
24 lines
385 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
)
|
|
|
|
func render(tmpl string, ctx TemplateContext) []byte {
|
|
funcMap := template.FuncMap{
|
|
"sh": ctx.inline,
|
|
"shell": ctx.codeBlock,
|
|
}
|
|
t, err := template.New("foo").Funcs(funcMap).Parse(tmpl)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var buf bytes.Buffer
|
|
err = t.Execute(&buf, ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return buf.Bytes()
|
|
}
|