package mdconv import ( "io" "text/template" "tildegit.org/tjp/sliderule/gopher" "tildegit.org/tjp/sliderule/gopher/gophermap/internal" ) func Convert(wr io.Writer, doc gopher.MapDocument, overrides *template.Template) error { tmpl, err := baseTmpl.Clone() if err != nil { return err } tmpl, err = internal.AddOverrides(tmpl, overrides) if err != nil { return err } for _, item := range internal.RenderItems(doc) { if err := tmpl.ExecuteTemplate(wr, item.Template, item.Object); err != nil { return err } } return nil } var baseTmpl = template.Must(template.New("mdconv").Parse(` {{ define "header" }}{{ end }} {{ define "message" -}} ` + "```" + ` {{.}} ` + "```" + ` {{ end }} {{ define "link" -}} [{{.Display}}]({{ if .Hostname | and .Port }}gopher://{{.Hostname}}:{{.Port}}{{ end }}{{.Selector}}) {{ end }} {{ define "image" -}} ![{{.Display}}]({{ if .Hostname | and .Port }}gopher://{{.Hostname}}:{{.Port}}{{ end }}{{.Selector}}) {{ end }} {{ define "footer" }}{{ end }} `))