about summary refs log tree commit diff stats
path: root/gomponents.go
diff options
context:
space:
mode:
authorMarkus Wüstenberg2020-09-23 22:10:35 +0200
committerGitHub2020-09-23 22:10:35 +0200
commitf27cb0c05f23785189979e57c831eb798e1da1f1 (patch)
tree902f20b3698d7470b4fa5769278319424463f88b /gomponents.go
parent3de9270f785082b70e5d3cb7212271d7ad86a6d9 (diff)
downloadgomponents-f27cb0c05f23785189979e57c831eb798e1da1f1.tar.lz
gomponents-f27cb0c05f23785189979e57c831eb798e1da1f1.tar.zst
gomponents-f27cb0c05f23785189979e57c831eb798e1da1f1.zip
Add Textf function (#17)
Like Text, but calls fmt.Sprintf before rendering.
Diffstat (limited to 'gomponents.go')
-rw-r--r--gomponents.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/gomponents.go b/gomponents.go
index d160b54..21d3e75 100644
--- a/gomponents.go
+++ b/gomponents.go
@@ -109,6 +109,13 @@ func Text(t string) NodeFunc {
 	}
 }
 
+// Textf creates a text DOM Node that Renders the interpolated and escaped string t.
+func Textf(format string, a ...interface{}) NodeFunc {
+	return func() string {
+		return template.HTMLEscaper(fmt.Sprintf(format, a...))
+	}
+}
+
 // Raw creates a raw Node that just Renders the unescaped string t.
 func Raw(t string) NodeFunc {
 	return func() string {