@@ -122,8 +122,23 @@ func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML {
122122 return ret
123123}
124124
125- // RenderLabel renders a label
125+ func (ut * RenderUtils ) RenderLabelWithLink (label * issues_model.Label , link any ) template.HTML {
126+ var attrHref template.HTML
127+ switch link .(type ) {
128+ case template.URL , string :
129+ attrHref = htmlutil .HTMLFormat (`href="%s"` , link )
130+ default :
131+ panic (fmt .Sprintf ("unexpected type %T for link" , link ))
132+ }
133+ return ut .renderLabelWithTag (label , "a" , attrHref )
134+ }
135+
126136func (ut * RenderUtils ) RenderLabel (label * issues_model.Label ) template.HTML {
137+ return ut .renderLabelWithTag (label , "span" , "" )
138+ }
139+
140+ // RenderLabel renders a label
141+ func (ut * RenderUtils ) renderLabelWithTag (label * issues_model.Label , tagName , tagAttrs template.HTML ) template.HTML {
127142 locale := ut .ctx .Value (translation .ContextKey ).(translation.Locale )
128143 var extraCSSClasses string
129144 textColor := util .ContrastColor (label .Color )
@@ -137,8 +152,8 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
137152
138153 if labelScope == "" {
139154 // Regular label
140- return htmlutil .HTMLFormat (`<div class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s"><span class="gt-ellipsis">%s</span></div >` ,
141- extraCSSClasses , textColor , label .Color , descriptionText , ut .RenderEmoji (label .Name ))
155+ return htmlutil .HTMLFormat (`<%s %s class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s"><span class="gt-ellipsis">%s</span></%s >` ,
156+ tagName , tagAttrs , extraCSSClasses , textColor , label .Color , descriptionText , ut .RenderEmoji (label .Name ), tagName )
142157 }
143158
144159 // Scoped label
@@ -152,7 +167,7 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
152167 // Ensure we add the same amount of contrast also near 0 and 1.
153168 darken := contrast + math .Max (luminance + contrast - 1.0 , 0.0 )
154169 lighten := contrast + math .Max (contrast - luminance , 0.0 )
155- // Compute factor to keep RGB values proportional.
170+ // Compute the factor to keep RGB values proportional.
156171 darkenFactor := math .Max (luminance - darken , 0.0 ) / math .Max (luminance , 1.0 / 255.0 )
157172 lightenFactor := math .Min (luminance + lighten , 1.0 ) / math .Max (luminance , 1.0 / 255.0 )
158173
@@ -173,26 +188,29 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
173188
174189 if label .ExclusiveOrder > 0 {
175190 // <scope> | <label> | <order>
176- return htmlutil .HTMLFormat (`<span class="ui label %s scope-parent" data-tooltip-content title="%s">` +
191+ return htmlutil .HTMLFormat (`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">` +
177192 `<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>` +
178193 `<div class="ui label scope-middle" style="color: %s !important; background-color: %s !important">%s</div>` +
179194 `<div class="ui label scope-right">%d</div>` +
180- `</span>` ,
195+ `</%s>` ,
196+ tagName , tagAttrs ,
181197 extraCSSClasses , descriptionText ,
182198 textColor , scopeColor , scopeHTML ,
183199 textColor , itemColor , itemHTML ,
184- label .ExclusiveOrder )
200+ label .ExclusiveOrder ,
201+ tagName )
185202 }
186203
187204 // <scope> | <label>
188- return htmlutil .HTMLFormat (`<span class="ui label %s scope-parent" data-tooltip-content title="%s">` +
205+ return htmlutil .HTMLFormat (`<%s %s class="ui label %s scope-parent" data-tooltip-content title="%s">` +
189206 `<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>` +
190207 `<div class="ui label scope-right" style="color: %s !important; background-color: %s !important">%s</div>` +
191208 `</span>` ,
209+ tagName , tagAttrs ,
192210 extraCSSClasses , descriptionText ,
193211 textColor , scopeColor , scopeHTML ,
194212 textColor , itemColor , itemHTML ,
195- )
213+ tagName )
196214}
197215
198216// RenderEmoji renders html text with emoji post processors
@@ -235,7 +253,8 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin
235253 if label == nil {
236254 continue
237255 }
238- htmlCode += fmt .Sprintf (`<a href="%s?labels=%d">%s</a>` , baseLink , label .ID , ut .RenderLabel (label ))
256+ link := fmt .Sprintf ("%s?labels=%d" , baseLink , label .ID )
257+ htmlCode += string (ut .RenderLabelWithLink (label , template .URL (link )))
239258 }
240259 htmlCode += "</span>"
241260 return template .HTML (htmlCode )
0 commit comments