package template import ( "regexp" "strings" ) var unresolvedPlaceholderPattern = regexp.MustCompile(`\{\{[a-zA-Z0-9_]+\}\}`) func RenderDoc(tmpl string, vars map[string]string) string { res := tmpl for k, v := range vars { placeholder := "{{" + k + "}}" res = strings.ReplaceAll(res, placeholder, v) } // Any variable that wasn't provided leaves a raw {{placeholder}} in the // output. Replace those with a clear "待确认" marker instead of leaking // template syntax into delivered documents. res = unresolvedPlaceholderPattern.ReplaceAllString(res, "待确认") return res }