enhance(markup): improve issue title rendering (#37908)

This commit is contained in:
silverwind
2026-05-30 18:55:26 +02:00
committed by GitHub
parent 0359746abe
commit 82cf75b68a
5 changed files with 53 additions and 5 deletions
+32
View File
@@ -180,6 +180,38 @@ mail@domain.com
})
}
func TestRenderIssueTitleCodeSpan(t *testing.T) {
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
mockRepo := &repo.Repository{
ID: 1, OwnerName: "user13", Name: "repo11",
Owner: &user_model.User{ID: 13, Name: "user13"},
Units: []*repo.RepoUnit{},
}
ut := newTestRenderUtils(t)
cases := []struct {
input string
expected string
emojiSafe bool
}{
{"foo `:100:`", `foo <code class="inline-code-block">:100:</code>`, true},
{"`#123`", `<code class="inline-code-block">#123</code>`, false},
{"`88fc37a3c0a4dda553bdcfc80c178a58247f42fb`", `<code class="inline-code-block">88fc37a3c0a4dda553bdcfc80c178a58247f42fb</code>`, false},
{"foo `:100:", "foo `:100:", true},
{"foo ` :100:", `foo ` + "`" + ` <span class="emoji" aria-label="hundred points">💯</span>`, true},
{":100:", `<span class="emoji" aria-label="hundred points">💯</span>`, true},
{"#123", `<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>`, false},
{"`x`:100:", `<code class="inline-code-block">x</code><span class="emoji" aria-label="hundred points">💯</span>`, true},
{"a `:100:` b `:+1:` c", `a <code class="inline-code-block">:100:</code> b <code class="inline-code-block">:+1:</code> c`, true},
}
for _, c := range cases {
assert.Equal(t, c.expected, string(ut.RenderIssueTitle(c.input, mockRepo)), "input=%q", c.input)
if c.emojiSafe {
assert.Equal(t, c.expected, string(ut.RenderIssueSimpleTitle(c.input)), "simple input=%q", c.input)
}
}
}
func TestRenderMarkdownToHtml(t *testing.T) {
defer test.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
expected := `<p>space <a href="/mention-user" rel="nofollow">@mention-user</a><br/>