@@ -36,7 +36,7 @@ func NewFuncMap() template.FuncMap {
36
36
"dict" : dict , // it's lowercase because this name has been widely used. Our other functions should have uppercase names.
37
37
"Eval" : Eval ,
38
38
"Safe" : Safe ,
39
- "Escape" : html . EscapeString ,
39
+ "Escape" : Escape ,
40
40
"QueryEscape" : url .QueryEscape ,
41
41
"JSEscape" : template .JSEscapeString ,
42
42
"Str2html" : Str2html , // TODO: rename it to SanitizeHTML
@@ -159,7 +159,7 @@ func NewFuncMap() template.FuncMap {
159
159
"RenderCodeBlock" : RenderCodeBlock ,
160
160
"RenderIssueTitle" : RenderIssueTitle ,
161
161
"RenderEmoji" : RenderEmoji ,
162
- "RenderEmojiPlain" : emoji . ReplaceAliases ,
162
+ "RenderEmojiPlain" : RenderEmojiPlain ,
163
163
"ReactionToEmoji" : ReactionToEmoji ,
164
164
165
165
"RenderMarkdownToHtml" : RenderMarkdownToHtml ,
@@ -180,13 +180,45 @@ func NewFuncMap() template.FuncMap {
180
180
}
181
181
182
182
// Safe render raw as HTML
183
- func Safe (raw string ) template.HTML {
184
- return template .HTML (raw )
183
+ func Safe (s any ) template.HTML {
184
+ switch v := s .(type ) {
185
+ case string :
186
+ return template .HTML (v )
187
+ case template.HTML :
188
+ return v
189
+ }
190
+ panic (fmt .Sprintf ("unexpected type %T" , s ))
191
+ }
192
+
193
+ // Str2html sanitizes the input by pre-defined markdown rules
194
+ func Str2html (s any ) template.HTML {
195
+ switch v := s .(type ) {
196
+ case string :
197
+ return template .HTML (markup .Sanitize (v ))
198
+ case template.HTML :
199
+ return template .HTML (markup .Sanitize (string (v )))
200
+ }
201
+ panic (fmt .Sprintf ("unexpected type %T" , s ))
185
202
}
186
203
187
- // Str2html render Markdown text to HTML
188
- func Str2html (raw string ) template.HTML {
189
- return template .HTML (markup .Sanitize (raw ))
204
+ func Escape (s any ) template.HTML {
205
+ switch v := s .(type ) {
206
+ case string :
207
+ return template .HTML (html .EscapeString (v ))
208
+ case template.HTML :
209
+ return v
210
+ }
211
+ panic (fmt .Sprintf ("unexpected type %T" , s ))
212
+ }
213
+
214
+ func RenderEmojiPlain (s any ) any {
215
+ switch v := s .(type ) {
216
+ case string :
217
+ return emoji .ReplaceAliases (v )
218
+ case template.HTML :
219
+ return template .HTML (emoji .ReplaceAliases (string (v )))
220
+ }
221
+ panic (fmt .Sprintf ("unexpected type %T" , s ))
190
222
}
191
223
192
224
// DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls
0 commit comments