From f92c3de9653a68fb0eed877fd76c20e431f58c97 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 25 Feb 2024 06:34:51 +0800 Subject: [PATCH] Remove RenderEmojiPlain from template helper (#29375) RenderEmojiPlain(emoji.ReplaceAliases) should be called explicitly for some contents, but not for everything. Actually in modern days, in most cases it doesn't need such "ReplaceAliases". So only keep it for issue/PR titles. If anyone really needs to do ReplaceAliases for some contents, I will propose a following fix. (cherry picked from commit 10c7996b5a5c705964fc6cc9c1817eea1fc436ef) Conflicts: templates/base/head.tmpl context --- modules/templates/helper.go | 12 ------------ routers/web/repo/issue.go | 3 ++- routers/web/repo/pull.go | 3 ++- templates/base/head.tmpl | 2 +- templates/repo/issue/choose.tmpl | 8 ++++---- templates/repo/settings/lfs_file_find.tmpl | 2 +- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 3bf1919b4..d2fe6a28c 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -14,7 +14,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" - "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/svg" @@ -162,7 +161,6 @@ func NewFuncMap() template.FuncMap { "RenderCodeBlock": RenderCodeBlock, "RenderIssueTitle": RenderIssueTitle, "RenderEmoji": RenderEmoji, - "RenderEmojiPlain": RenderEmojiPlain, "ReactionToEmoji": ReactionToEmoji, "RenderMarkdownToHtml": RenderMarkdownToHtml, @@ -218,16 +216,6 @@ func JSEscapeSafe(s string) template.HTML { return template.HTML(template.JSEscapeString(s)) } -func RenderEmojiPlain(s any) any { - switch v := s.(type) { - case string: - return emoji.ReplaceAliases(v) - case template.HTML: - return template.HTML(emoji.ReplaceAliases(string(v))) - } - panic(fmt.Sprintf("unexpected type %T", s)) -} - // DotEscape wraps a dots in names with ZWJ [U+200D] in order to prevent autolinkers from detecting these as urls func DotEscape(raw string) string { return strings.ReplaceAll(raw, ".", "\u200d.\u200d") diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 1a598029c..05db10754 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -32,6 +32,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/git" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" issue_template "code.gitea.io/gitea/modules/issue/template" @@ -1444,7 +1445,7 @@ func ViewIssue(ctx *context.Context) { return } - ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title) + ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title)) iw := new(issues_model.IssueWatch) if ctx.Doer != nil { diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index dcb062350..949962ad6 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -29,6 +29,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/gitrepo" issue_template "code.gitea.io/gitea/modules/issue/template" @@ -346,7 +347,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) { ctx.ServerError("LoadRepo", err) return nil, false } - ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title) + ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title)) ctx.Data["Issue"] = issue if !issue.IsPull { diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index a202ad7dd..ad3419793 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -3,7 +3,7 @@ {{/* Display `- .Repsository.FullName` only if `.Title` does not already start with that. */}} - {{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}}{{if and (.Repository.Name) (not (StringUtils.HasPrefix .Title .Repository.FullName))}}{{.Repository.FullName}} - {{end}}{{AppName}} + {{if .Title}}{{.Title}} - {{end}}{{if and (.Repository.Name) (not (StringUtils.HasPrefix .Title .Repository.FullName))}}{{.Repository.FullName}} - {{end}}{{AppName}} {{if .ManifestData}}{{end}} diff --git a/templates/repo/issue/choose.tmpl b/templates/repo/issue/choose.tmpl index 127b9d7d8..a8037482b 100644 --- a/templates/repo/issue/choose.tmpl +++ b/templates/repo/issue/choose.tmpl @@ -11,8 +11,8 @@
- {{.Name | RenderEmojiPlain}} -
{{.About | RenderEmojiPlain}} + {{.Name}} +
{{.About}}
{{ctx.Locale.Tr "repo.issues.choose.get_started"}} @@ -24,8 +24,8 @@
- {{.Name | RenderEmojiPlain}} -
{{.About | RenderEmojiPlain}} + {{.Name}} +
{{.About}}
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues.choose.open_external_link"}} diff --git a/templates/repo/settings/lfs_file_find.tmpl b/templates/repo/settings/lfs_file_find.tmpl index fea9aa323..809a028b2 100644 --- a/templates/repo/settings/lfs_file_find.tmpl +++ b/templates/repo/settings/lfs_file_find.tmpl @@ -14,7 +14,7 @@ - + {{.Summary | RenderEmoji $.Context}}