@@ -122,8 +122,23 @@ func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML {
122
122
return ret
123
123
}
124
124
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
+
126
136
func (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 {
127
142
locale := ut .ctx .Value (translation .ContextKey ).(translation.Locale )
128
143
var extraCSSClasses string
129
144
textColor := util .ContrastColor (label .Color )
@@ -137,8 +152,8 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
137
152
138
153
if labelScope == "" {
139
154
// Regular label
140
- return htmlutil .HTMLFormat (`<div class="ui label %s" style="color: %s !important; background-color: %s !important;" data-tooltip-content title="%s">%s</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 )
142
157
}
143
158
144
159
// Scoped label
@@ -152,7 +167,7 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
152
167
// Ensure we add the same amount of contrast also near 0 and 1.
153
168
darken := contrast + math .Max (luminance + contrast - 1.0 , 0.0 )
154
169
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.
156
171
darkenFactor := math .Max (luminance - darken , 0.0 ) / math .Max (luminance , 1.0 / 255.0 )
157
172
lightenFactor := math .Min (luminance + lighten , 1.0 ) / math .Max (luminance , 1.0 / 255.0 )
158
173
@@ -173,26 +188,29 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML {
173
188
174
189
if label .ExclusiveOrder > 0 {
175
190
// <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">` +
177
192
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>` +
178
193
`<div class="ui label scope-middle" style="color: %s !important; background-color: %s !important">%s</div>` +
179
194
`<div class="ui label scope-right">%d</div>` +
180
- `</span>` ,
195
+ `</%s>` ,
196
+ tagName , tagAttrs ,
181
197
extraCSSClasses , descriptionText ,
182
198
textColor , scopeColor , scopeHTML ,
183
199
textColor , itemColor , itemHTML ,
184
- label .ExclusiveOrder )
200
+ label .ExclusiveOrder ,
201
+ tagName )
185
202
}
186
203
187
204
// <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">` +
189
206
`<div class="ui label scope-left" style="color: %s !important; background-color: %s !important">%s</div>` +
190
207
`<div class="ui label scope-right" style="color: %s !important; background-color: %s !important">%s</div>` +
191
- `</span>` ,
208
+ `</%s>` ,
209
+ tagName , tagAttrs ,
192
210
extraCSSClasses , descriptionText ,
193
211
textColor , scopeColor , scopeHTML ,
194
212
textColor , itemColor , itemHTML ,
195
- )
213
+ tagName )
196
214
}
197
215
198
216
// RenderEmoji renders html text with emoji post processors
@@ -235,7 +253,8 @@ func (ut *RenderUtils) RenderLabels(labels []*issues_model.Label, repoLink strin
235
253
if label == nil {
236
254
continue
237
255
}
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 )))
239
258
}
240
259
htmlCode += "</span>"
241
260
return template .HTML (htmlCode )
0 commit comments