Can I render a template md file as just text (i.e back to markdown)

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
        }
}

.RawContent returns the raw Markdown of a file. However, I’m not sure what the above code is (my skill level isn’t as much). So, I don’t know how you can implement it. But yeah, the Hugo page variable you’re probably looking for is .RawContent. Check it out here: https://gohugo.io/variables/page/#page-variables

You can configure Hugo to generate md as a custom output format: https://gohugo.io/templates/output-formats