From f27cb0c05f23785189979e57c831eb798e1da1f1 Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Wed, 23 Sep 2020 22:10:35 +0200 Subject: Add Textf function (#17) Like Text, but calls fmt.Sprintf before rendering.--- gomponents.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gomponents.go') 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 { -- cgit 1.4.1