@@ -35,6 +35,7 @@ import (
3535 "code.gitea.io/gitea/modules/emoji"
3636 "code.gitea.io/gitea/modules/git"
3737 giturl "code.gitea.io/gitea/modules/git/url"
38+ gitea_html "code.gitea.io/gitea/modules/html"
3839 "code.gitea.io/gitea/modules/json"
3940 "code.gitea.io/gitea/modules/log"
4041 "code.gitea.io/gitea/modules/markup"
@@ -348,7 +349,7 @@ func NewFuncMap() []template.FuncMap {
348349 }
349350 return false
350351 },
351- "svg" : SVG ,
352+ "svg" : svg . RenderHTML ,
352353 "avatar" : Avatar ,
353354 "avatarHTML" : AvatarHTML ,
354355 "avatarByAction" : AvatarByAction ,
@@ -363,17 +364,17 @@ func NewFuncMap() []template.FuncMap {
363364 if len (urlSort ) == 0 && isDefault {
364365 // if sort is sorted as default add arrow tho this table header
365366 if isDefault {
366- return SVG ("octicon-triangle-down" , 16 )
367+ return svg . RenderHTML ("octicon-triangle-down" , 16 )
367368 }
368369 } else {
369370 // if sort arg is in url test if it correlates with column header sort arguments
370371 // the direction of the arrow should indicate the "current sort order", up means ASC(normal), down means DESC(rev)
371372 if urlSort == normSort {
372373 // the table is sorted with this header normal
373- return SVG ("octicon-triangle-up" , 16 )
374+ return svg . RenderHTML ("octicon-triangle-up" , 16 )
374375 } else if urlSort == revSort {
375376 // the table is sorted with this header reverse
376- return SVG ("octicon-triangle-down" , 16 )
377+ return svg . RenderHTML ("octicon-triangle-down" , 16 )
377378 }
378379 }
379380 // the table is NOT sorted with this header
@@ -594,29 +595,6 @@ func NewTextFuncMap() []texttmpl.FuncMap {
594595 }}
595596}
596597
597- var (
598- widthRe = regexp .MustCompile (`width="[0-9]+?"` )
599- heightRe = regexp .MustCompile (`height="[0-9]+?"` )
600- )
601-
602- func parseOthers (defaultSize int , defaultClass string , others ... interface {}) (int , string ) {
603- size := defaultSize
604- if len (others ) > 0 && others [0 ].(int ) != 0 {
605- size = others [0 ].(int )
606- }
607-
608- class := defaultClass
609- if len (others ) > 1 && others [1 ].(string ) != "" {
610- if defaultClass == "" {
611- class = others [1 ].(string )
612- } else {
613- class = defaultClass + " " + others [1 ].(string )
614- }
615- }
616-
617- return size , class
618- }
619-
620598// AvatarHTML creates the HTML for an avatar
621599func AvatarHTML (src string , size int , class , name string ) template.HTML {
622600 sizeStr := fmt .Sprintf (`%d` , size )
@@ -628,26 +606,9 @@ func AvatarHTML(src string, size int, class, name string) template.HTML {
628606 return template .HTML (`<img class="` + class + `" src="` + src + `" title="` + html .EscapeString (name ) + `" width="` + sizeStr + `" height="` + sizeStr + `"/>` )
629607}
630608
631- // SVG render icons - arguments icon name (string), size (int), class (string)
632- func SVG (icon string , others ... interface {}) template.HTML {
633- size , class := parseOthers (16 , "" , others ... )
634-
635- if svgStr , ok := svg .SVGs [icon ]; ok {
636- if size != 16 {
637- svgStr = widthRe .ReplaceAllString (svgStr , fmt .Sprintf (`width="%d"` , size ))
638- svgStr = heightRe .ReplaceAllString (svgStr , fmt .Sprintf (`height="%d"` , size ))
639- }
640- if class != "" {
641- svgStr = strings .Replace (svgStr , `class="` , fmt .Sprintf (`class="%s ` , class ), 1 )
642- }
643- return template .HTML (svgStr )
644- }
645- return template .HTML ("" )
646- }
647-
648609// Avatar renders user avatars. args: user, size (int), class (string)
649610func Avatar (item interface {}, others ... interface {}) template.HTML {
650- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar vm" , others ... )
611+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar vm" , others ... )
651612
652613 switch t := item .(type ) {
653614 case * user_model.User :
@@ -678,7 +639,7 @@ func AvatarByAction(action *activities_model.Action, others ...interface{}) temp
678639
679640// RepoAvatar renders repo avatars. args: repo, size(int), class (string)
680641func RepoAvatar (repo * repo_model.Repository , others ... interface {}) template.HTML {
681- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
642+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
682643
683644 src := repo .RelAvatarLink ()
684645 if src != "" {
@@ -689,7 +650,7 @@ func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTM
689650
690651// AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
691652func AvatarByEmail (email , name string , others ... interface {}) template.HTML {
692- size , class := parseOthers (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
653+ size , class := gitea_html . ParseSizeAndClass (avatars .DefaultAvatarPixelSize , "ui avatar" , others ... )
693654 src := avatars .GenerateEmailAvatarFastLink (email , size * setting .Avatar .RenderedSizeFactor )
694655
695656 if src != "" {
0 commit comments