From 37df33e09316c105294d4a73cf56819b9a738a8c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 2 Aug 2025 01:20:00 +0200 Subject: Improve table formatting --- src/templates.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/templates.go') diff --git a/src/templates.go b/src/templates.go index a3bc52d..ec081f1 100644 --- a/src/templates.go +++ b/src/templates.go @@ -33,6 +33,7 @@ var ( "safe": asHTML, "toUpper": strings.ToUpper, "tuple": templateMakeTuple, + "withTranslation": withTranslation, "withTranslations": withTranslations, } ) @@ -119,6 +120,28 @@ func ifElse(b bool, x, y any) any { return y } +func withTranslation(tag, bcp, text string, trans template.HTML) template.HTML { + var bob strings.Builder + bob.WriteByte('<') + bob.WriteString(tag) + bob.WriteString(`>`) + bob.WriteString(text) + bob.WriteString("") + + if text != string(trans) { + bob.WriteString(`
`) + bob.WriteString(string(trans)) + bob.WriteString("") + } + + bob.WriteString("') + return template.HTML(bob.String()) +} + func withTranslations(tag string, text string, translations ...[]any) template.HTML { var bob strings.Builder bob.WriteByte('<') -- cgit v1.2.3