I was hoping to use Hugo (ie. go templates) to render obviously html but also in the case of a readme.md file back into markdown so it can be used in git repo. One markdown file containing go template syntax to both output formats.
According to the docs Hugo uses text/template ie.golang text/template.
So rather than make my own text/template renderer is it possible (via cli or a module) to get Hugo to take a single content file (e.g. readme.md) and render it back as markdown instead of into html?
Not that it’s that hard to do this like below but as function accepting the template (ie. md) and data object. I’m only wondering if it’s supported because Hugo is already using text/template.
package main
import (
"log"
"os"
"text/template"
)
type Person struct {
Name string
Emails []string
}
const tmpl = `
# {{$name := .Name}}
{{range .Emails}}
**Name is {{$name}}, email is {{.}}**
{{end}}
`
func main() {
person := Person{
Name: "Satish",
Emails: []string{"satish@rubylearning.org", "satishtalim@gmail.com"},
}
t := template.New("Person template")
t, err := t.Parse(tmpl)
if err != nil {
log.Fatal("Parse: ", err)
return
}
err = t.Execute(os.Stdout, person)
if err != nil {
log.Fatal("Execute: ", err)
return
}
}