Files
coder/coderd/notifications/render/gotmpl.go
T
Jakub Domeracki 8c2f7adeb1 revert: "fix: markdown rendering improvements" (#27979)
This reverts commit 07f79af65b ("fix:
markdown rendering improvements").

The revert was applied cleanly with `git revert` and restores the
notification rendering pipeline to its prior state, including:

- `coderd/notifications/dispatch/smtp.go` and `smtp/html.gotmpl`
- `coderd/notifications/notifier.go` and `render/gotmpl.go`
- Removal of `coderd/notifications/render/sanitize_test.go` and
`smtp_internal_test.go` additions
- Regenerated SMTP golden templates under
`coderd/notifications/testdata/`

`go build ./coderd/notifications/...` passes on the reverted tree.

---

_This PR was generated by Coder Agents on behalf of @jdomeracki-coder._
2026-08-10 12:58:01 +02:00

36 lines
1020 B
Go

package render
import (
"strings"
"text/template"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/notifications/types"
)
// NoValue is used when a template variable is not found.
// This string is not exported as a const from the text/template.
const NoValue = "<no value>"
// GoTemplate attempts to substitute the given payload into the given template using Go's templating syntax.
// TODO: memoize templates for memory efficiency?
func GoTemplate(in string, payload types.MessagePayload, extraFuncs template.FuncMap) (string, error) {
tmpl, err := template.New("text").
Funcs(extraFuncs).
// text/template substitutes a missing label with "<no value>".
// NOTE: html/template does not, for obvious reasons.
Option("missingkey=invalid").
Parse(in)
if err != nil {
return "", xerrors.Errorf("template parse: %w", err)
}
var out strings.Builder
if err = tmpl.Execute(&out, payload); err != nil {
return "", xerrors.Errorf("template execute: %w", err)
}
return out.String(), nil
}