From 6f991de19fabb2323f028bc7775f8b8cd94a341f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 27 May 2021 23:33:23 +0200 Subject: [PATCH 01/13] add "codeberg" emoji --- modules/markup/html.go | 2 +- public/img/emoji/codeberg.png | Bin 0 -> 8317 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 public/img/emoji/codeberg.png diff --git a/modules/markup/html.go b/modules/markup/html.go index 4d1b49e24155..20d73281c2ed 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -916,7 +916,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) { converted := emoji.FromAlias(alias) if converted == nil { // check if this is a custom reaction - s := strings.Join(setting.UI.Reactions, " ") + "gitea" + s := strings.Join(setting.UI.Reactions, " ") + "gitea" + "codeberg" if strings.Contains(s, alias) { replaceContent(node, m[0], m[1], createCustomEmoji(alias, "emoji")) return diff --git a/public/img/emoji/codeberg.png b/public/img/emoji/codeberg.png new file mode 100644 index 0000000000000000000000000000000000000000..b91613833a2ffafc514facb6beac699ee8973b89 GIT binary patch literal 8317 zcmW+*by!qS7rsl#64D`3%hKH`%_1c!(j5W{EV0B=E+A4$Np}ed0)liaNDC6u9n!Tl z65sy5KjzN!%)E2voH_5znKL&^S6lTV!D9jd03NEV!SpfpD5ms*A7H*dYdEc#3g2DL z#0vnvOaE6u@!W4MF^#kc6=TG6_)CPZji&?P>+8$!?DpEr&c@w=AMWXxc_8x`1ETv6 zWZ;Z&aR8Lz_71iVo{kU~xFa0$(#FTx4(`^(z%7b_QU3>1^hP+rJpp|<28DoV*?1zH z-5mVuuZx5*h)4e+lsz465YBKnh=H@K10XCYEXXG)#wQ{Kb zNvA9TfJsXorfA@owVxg2XYnHYuw$w2LQ37#)QOOWHi4b2`!%cj9Jp^t#;9tjaLe1E zh{}qzTkmPxDvH20@dw!~RG8bp&F?rGURbDa1)P!C>jioAVry3Fp4X(@=9iHZgE6mj%iWeh^tNR{Rof(#7d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FY9^x2LG8D=GiKm=b;z^GJv&y5g$tW{^Rj-4t72}{AGzJT^0)|h^Ln;kIrMQd#@ zNHtHtC3^d_Suw`3UP`%b>r$J)J<_)|Sl6q8#RJUsNjZGjkP}0U!K}{~OXt$jyjhp& z@x9B9I^K)d(Ith#4$M{7`RWc}#+4@;z@MS5( p7emjnEqkZO>&+fUa6|5yn)c+wQj<7CFhA-6bro$`rIK~%{{Vrfva$dG literal 0 HcmV?d00001 From 3c82f01c8b5e4a4b1808e06c15155bd121a28f48 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 1 Jun 2021 23:14:21 +0200 Subject: [PATCH 02/13] WIP --- modules/markup/html.go | 5 ++--- modules/markup/html_test.go | 7 +++++++ modules/setting/setting.go | 4 +++- modules/structs/settings.go | 1 + routers/api/v1/settings/settings.go | 1 + web_src/js/features/emoji.js | 8 +++++--- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 20d73281c2ed..6f451d682943 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -66,7 +66,7 @@ var ( blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`) // EmojiShortCodeRegex find emoji by alias like :smile: - EmojiShortCodeRegex = regexp.MustCompile(`\:[\w\+\-]+\:{1}`) + EmojiShortCodeRegex = regexp.MustCompile(`\:[\w\+\-]+\:`) ) // CSS class for action keywords (e.g. "closes: #1") @@ -916,8 +916,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) { converted := emoji.FromAlias(alias) if converted == nil { // check if this is a custom reaction - s := strings.Join(setting.UI.Reactions, " ") + "gitea" + "codeberg" - if strings.Contains(s, alias) { + if util.ExistsInSlice(alias, setting.UI.CustomEmojis) { replaceContent(node, m[0], m[1], createCustomEmoji(alias, "emoji")) return } diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index fa8c848601fe..0e77975f88fe 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -284,6 +284,13 @@ func TestRender_emoji(t *testing.T) { test( ":gitea:", `

:gitea:

`) + test( + ":custom-emoji:", + `

:custom-emoji:

`) + setting.UI.CustomEmojis = append(setting.UI.CustomEmojis, "custom-emoji") + test( + ":custom-emoji:", + `

:custom-emoji:

`) test( "Some text with πŸ˜„ in the middle", diff --git a/modules/setting/setting.go b/modules/setting/setting.go index c16520572d35..e4e0fa7b2d16 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -198,7 +198,8 @@ var ( DefaultTheme string Themes []string Reactions []string - ReactionsMap map[string]bool + ReactionsMap map[string]bool `ini:"-"` + CustomEmojis []string SearchRepoDescription bool UseServiceWorker bool @@ -246,6 +247,7 @@ var ( DefaultTheme: `gitea`, Themes: []string{`gitea`, `arc-green`}, Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`}, + CustomEmojis: []string{`gitea`, `codeberg`}, Notification: struct { MinTimeout time.Duration TimeoutStep time.Duration diff --git a/modules/structs/settings.go b/modules/structs/settings.go index 842b12792d1d..90c4a2107bbd 100644 --- a/modules/structs/settings.go +++ b/modules/structs/settings.go @@ -18,6 +18,7 @@ type GeneralRepoSettings struct { type GeneralUISettings struct { DefaultTheme string `json:"default_theme"` AllowedReactions []string `json:"allowed_reactions"` + CustomEmojis []string `json:"custom_emojis"` } // GeneralAPISettings contains global api settings exposed by it diff --git a/routers/api/v1/settings/settings.go b/routers/api/v1/settings/settings.go index e6417e40748c..ca2d28fb8bf2 100644 --- a/routers/api/v1/settings/settings.go +++ b/routers/api/v1/settings/settings.go @@ -25,6 +25,7 @@ func GetGeneralUISettings(ctx *context.APIContext) { ctx.JSON(http.StatusOK, api.GeneralUISettings{ DefaultTheme: setting.UI.DefaultTheme, AllowedReactions: setting.UI.Reactions, + CustomEmojis: setting.UI.CustomEmojis, }) } diff --git a/web_src/js/features/emoji.js b/web_src/js/features/emoji.js index 7a522b95fc63..ecd751e4ef8b 100644 --- a/web_src/js/features/emoji.js +++ b/web_src/js/features/emoji.js @@ -2,7 +2,8 @@ import emojis from '../../../assets/emoji.json'; const {AssetUrlPrefix} = window.config; -const tempMap = {gitea: ':gitea:'}; +// TODO: use setting.UI.CustomEmojis +const tempMap = {gitea: ':gitea:', codeberg: ':codeberg:'}; for (const {emoji, aliases} of emojis) { for (const alias of aliases || []) { tempMap[alias] = emoji; @@ -23,8 +24,9 @@ for (const key of emojiKeys) { // retrieve HTML for given emoji name export function emojiHTML(name) { let inner; - if (name === 'gitea') { - inner = `:${name}:`; + // TODO: use setting.UI.CustomEmojis + if (name === 'gitea' || name === 'codeberg') { + inner = `:${name}:`; } else { inner = emojiString(name); } From 866339435b78ac65f1e5852c45d1c3f201c6d4bd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 02:39:39 +0200 Subject: [PATCH 03/13] do UI part --- modules/templates/helper.go | 7 +++++++ templates/base/head.tmpl | 1 + web_src/js/features/emoji.js | 7 +++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 83359a6ef234..0e1406c10074 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -90,6 +90,13 @@ func NewFuncMap() []template.FuncMap { "AllowedReactions": func() []string { return setting.UI.Reactions }, + "CustomEmojis": func() map[string]string { + result := make(map[string]string) + for _, emoji := range setting.UI.CustomEmojis { + result[emoji] = fmt.Sprintf(":%s:", emoji) + } + return result + }, "Safe": Safe, "SafeJS": SafeJS, "JSEscape": JSEscape, diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index 10fc2bad4a02..5091eda1e996 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -30,6 +30,7 @@ AppVer: '{{AppVer}}', AppSubUrl: '{{AppSubUrl}}', AssetUrlPrefix: '{{AssetUrlPrefix}}', + CustomEmojis: {{CustomEmojis}}, UseServiceWorker: {{UseServiceWorker}}, csrf: '{{.CsrfToken}}', HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}}, diff --git a/web_src/js/features/emoji.js b/web_src/js/features/emoji.js index ecd751e4ef8b..254a0b5c4d92 100644 --- a/web_src/js/features/emoji.js +++ b/web_src/js/features/emoji.js @@ -1,9 +1,9 @@ import emojis from '../../../assets/emoji.json'; const {AssetUrlPrefix} = window.config; +const {CustomEmojis} = window.config; -// TODO: use setting.UI.CustomEmojis -const tempMap = {gitea: ':gitea:', codeberg: ':codeberg:'}; +const tempMap = {...CustomEmojis}; for (const {emoji, aliases} of emojis) { for (const alias of aliases || []) { tempMap[alias] = emoji; @@ -24,8 +24,7 @@ for (const key of emojiKeys) { // retrieve HTML for given emoji name export function emojiHTML(name) { let inner; - // TODO: use setting.UI.CustomEmojis - if (name === 'gitea' || name === 'codeberg') { + if (Object.prototype.hasOwnProperty.call(CustomEmojis, name)) { inner = `:${name}:`; } else { inner = emojiString(name); From 3951cf2fa08ecfb29dbc71c82ebb8565d776ebe2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 02:56:41 +0200 Subject: [PATCH 04/13] calc CustomEmojisMap once --- modules/markup/html.go | 2 +- modules/setting/setting.go | 5 +++++ modules/templates/helper.go | 6 +----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index d94416860b27..604ebe5ebe14 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -948,7 +948,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) { converted := emoji.FromAlias(alias) if converted == nil { // check if this is a custom reaction - if util.ExistsInSlice(alias, setting.UI.CustomEmojis) { + if _, exist := setting.UI.CustomEmojisMap[alias]; exist { replaceContent(node, m[0], m[1], createCustomEmoji(alias, "emoji")) node = node.NextSibling.NextSibling start = 0 diff --git a/modules/setting/setting.go b/modules/setting/setting.go index c15713aee715..2a38d9fa8ebc 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -210,6 +210,7 @@ var ( Reactions []string ReactionsMap map[string]bool `ini:"-"` CustomEmojis []string + CustomEmojisMap map[string]string `ini:"-"` SearchRepoDescription bool UseServiceWorker bool @@ -985,6 +986,10 @@ func NewContext() { for _, reaction := range UI.Reactions { UI.ReactionsMap[reaction] = true } + UI.CustomEmojisMap = make(map[string]string) + for _, emoji := range UI.CustomEmojis { + UI.CustomEmojisMap[emoji] = fmt.Sprintf(":%s:", emoji) + } } func parseAuthorizedPrincipalsAllow(values []string) ([]string, bool) { diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 0e1406c10074..f9b2dafd22a1 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -91,11 +91,7 @@ func NewFuncMap() []template.FuncMap { return setting.UI.Reactions }, "CustomEmojis": func() map[string]string { - result := make(map[string]string) - for _, emoji := range setting.UI.CustomEmojis { - result[emoji] = fmt.Sprintf(":%s:", emoji) - } - return result + return setting.UI.CustomEmojisMap }, "Safe": Safe, "SafeJS": SafeJS, From c51fcd0777fbf035d5fbf8b595fb4f187642b631 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 02:57:06 +0200 Subject: [PATCH 05/13] refactor createCustomEmoji --- modules/markup/html.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 604ebe5ebe14..5d77234947a2 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -460,17 +460,14 @@ func createEmoji(content, class, name string) *html.Node { return span } -func createCustomEmoji(alias, class string) *html.Node { - +func createCustomEmoji(alias string) *html.Node { span := &html.Node{ Type: html.ElementNode, Data: atom.Span.String(), Attr: []html.Attribute{}, } - if class != "" { - span.Attr = append(span.Attr, html.Attribute{Key: "class", Val: class}) - span.Attr = append(span.Attr, html.Attribute{Key: "aria-label", Val: alias}) - } + span.Attr = append(span.Attr, html.Attribute{Key: "class", Val: "emoji"}) + span.Attr = append(span.Attr, html.Attribute{Key: "aria-label", Val: alias}) img := &html.Node{ Type: html.ElementNode, @@ -478,10 +475,8 @@ func createCustomEmoji(alias, class string) *html.Node { Data: "img", Attr: []html.Attribute{}, } - if class != "" { - img.Attr = append(img.Attr, html.Attribute{Key: "alt", Val: fmt.Sprintf(`:%s:`, alias)}) - img.Attr = append(img.Attr, html.Attribute{Key: "src", Val: fmt.Sprintf(`%s/assets/img/emoji/%s.png`, setting.StaticURLPrefix, alias)}) - } + img.Attr = append(img.Attr, html.Attribute{Key: "alt", Val: fmt.Sprintf(`:%s:`, alias)}) + img.Attr = append(img.Attr, html.Attribute{Key: "src", Val: fmt.Sprintf(`%s/assets/img/emoji/%s.png`, setting.StaticURLPrefix, alias)}) span.AppendChild(img) return span @@ -949,7 +944,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) { if converted == nil { // check if this is a custom reaction if _, exist := setting.UI.CustomEmojisMap[alias]; exist { - replaceContent(node, m[0], m[1], createCustomEmoji(alias, "emoji")) + replaceContent(node, m[0], m[1], createCustomEmoji(alias)) node = node.NextSibling.NextSibling start = 0 continue From 9769c8fa37e3f482d78b7ddca8bceb60a174897d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 03:30:28 +0200 Subject: [PATCH 06/13] extend tests --- modules/markup/html_test.go | 8 ++++++-- modules/setting/setting.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 157c86f72857..3353cda724e3 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -287,11 +287,15 @@ func TestRender_emoji(t *testing.T) { test( ":custom-emoji:", `

:custom-emoji:

`) - setting.UI.CustomEmojis = append(setting.UI.CustomEmojis, "custom-emoji") + setting.UI.CustomEmojisMap["custom-emoji"] = ":custom-emoji:" test( ":custom-emoji:", `

:custom-emoji:

`) - + test( + "a :+1: some🐊 \U0001f44d:custom-emoji: :gitea:", + `

a πŸ‘ some🐊 `+ + `πŸ‘:custom-emoji: `+ + `:gitea:

`) test( "Some text with πŸ˜„ in the middle", `

Some text with πŸ˜„ in the middle

`) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 2a38d9fa8ebc..3eac8c32b06e 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -259,6 +259,7 @@ var ( Themes: []string{`gitea`, `arc-green`}, Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`}, CustomEmojis: []string{`gitea`, `codeberg`}, + CustomEmojisMap: map[string]string{"gitea": ":gitea:", "codeberg": ":codeberg:"}, Notification: struct { MinTimeout time.Duration TimeoutStep time.Duration From b11a4aa5bcab5c3fe8e13c074024baba049e4e9f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 03:32:54 +0200 Subject: [PATCH 07/13] update swagger docs --- templates/swagger/v1_json.tmpl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 7f7907b3b0c6..40dddb06a078 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -14481,6 +14481,13 @@ }, "x-go-name": "AllowedReactions" }, + "custom_emojis": { + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "CustomEmojis" + }, "default_theme": { "type": "string", "x-go-name": "DefaultTheme" From 4e2c217f136a4f70519280a5880a0997c3c0255c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 03:40:22 +0200 Subject: [PATCH 08/13] add test case for #16060 --- modules/markup/html_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 3353cda724e3..85418892ef7f 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -292,8 +292,8 @@ func TestRender_emoji(t *testing.T) { ":custom-emoji:", `

:custom-emoji:

`) test( - "a :+1: some🐊 \U0001f44d:custom-emoji: :gitea:", - `

a πŸ‘ some🐊 `+ + "θΏ™ζ˜―ε­—η¬¦:1::+1: some🐊 \U0001f44d:custom-emoji: :gitea:", + `

θΏ™ζ˜―ε­—η¬¦:1:πŸ‘ some🐊 `+ `πŸ‘:custom-emoji: `+ `:gitea:

`) test( From 04edd2d235226e9153b657b1c9c4f5eabe44857e Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 11:43:36 +0200 Subject: [PATCH 09/13] =?UTF-8?q?remove=20codeberg=20=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/setting/setting.go | 4 ++-- public/img/emoji/codeberg.png | Bin 8317 -> 0 bytes 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 public/img/emoji/codeberg.png diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 3eac8c32b06e..405d28654fe8 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -258,8 +258,8 @@ var ( DefaultTheme: `gitea`, Themes: []string{`gitea`, `arc-green`}, Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`}, - CustomEmojis: []string{`gitea`, `codeberg`}, - CustomEmojisMap: map[string]string{"gitea": ":gitea:", "codeberg": ":codeberg:"}, + CustomEmojis: []string{`gitea`}, + CustomEmojisMap: map[string]string{"gitea": ":gitea:"}, Notification: struct { MinTimeout time.Duration TimeoutStep time.Duration diff --git a/public/img/emoji/codeberg.png b/public/img/emoji/codeberg.png deleted file mode 100644 index b91613833a2ffafc514facb6beac699ee8973b89..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8317 zcmW+*by!qS7rsl#64D`3%hKH`%_1c!(j5W{EV0B=E+A4$Np}ed0)liaNDC6u9n!Tl z65sy5KjzN!%)E2voH_5znKL&^S6lTV!D9jd03NEV!S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3Cu(v%aDAm48NOF9tO1`yW?iu}tWD?QC8p;sFX`#(EnvlOA5TU$EQR zzb;5=P8#F}9w4`lEm+WhTlHiZGk|e0l zMmc1qqkr=0X05GB#h$zP4kuDzF@gjY3*wty3z>Kx{8ltW*KaI%5obF7zcV@V!(I=A zWrORDV7tP`E&t5ppb!AV3e}uvZ8xRRKp?+g*~qzhI^dV??O#lM5E&}^z<8e1mnibb zx4~iu=UPRCDWQE%{Jbttp89gmbLL=F^c-Urt;DC;XZKp~7Q_KvjndINQOWB$TT1X( z5^7#A<}G=w65Ahm=~hTU;kkCV{^$Jw3ayb5=P*duG-hr`Y4TKhyg$~4MvOqga+K1) zI?FY9^x2LG8D=GiKm=b;z^GJv&y5g$tW{^Rj-4t72}{AGzJT^0)|h^Ln;kIrMQd#@ zNHtHtC3^d_Suw`3UP`%b>r$J)J<_)|Sl6q8#RJUsNjZGjkP}0U!K}{~OXt$jyjhp& z@x9B9I^K)d(Ith#4$M{7`RWc}#+4@;z@MS5( p7emjnEqkZO>&+fUa6|5yn)c+wQj<7CFhA-6bro$`rIK~%{{Vrfva$dG From ca7577f6c902d1f38f53dda4edf9a112079c2807 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 11:50:29 +0200 Subject: [PATCH 10/13] use "+" instead "of fmt.Sprintf()" --- modules/markup/html.go | 5 ++--- modules/setting/setting.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 5d77234947a2..3e9d22438a6f 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -6,7 +6,6 @@ package markup import ( "bytes" - "fmt" "io" "io/ioutil" "net/url" @@ -475,8 +474,8 @@ func createCustomEmoji(alias string) *html.Node { Data: "img", Attr: []html.Attribute{}, } - img.Attr = append(img.Attr, html.Attribute{Key: "alt", Val: fmt.Sprintf(`:%s:`, alias)}) - img.Attr = append(img.Attr, html.Attribute{Key: "src", Val: fmt.Sprintf(`%s/assets/img/emoji/%s.png`, setting.StaticURLPrefix, alias)}) + img.Attr = append(img.Attr, html.Attribute{Key: "alt", Val: ":" + alias + ":"}) + img.Attr = append(img.Attr, html.Attribute{Key: "src", Val: setting.StaticURLPrefix + "/assets/img/emoji/" + alias + ".png"}) span.AppendChild(img) return span diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 405d28654fe8..e37b78834202 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -989,7 +989,7 @@ func NewContext() { } UI.CustomEmojisMap = make(map[string]string) for _, emoji := range UI.CustomEmojis { - UI.CustomEmojisMap[emoji] = fmt.Sprintf(":%s:", emoji) + UI.CustomEmojisMap[emoji] = ":" + emoji + ":" } } From c291d2352431f82081e6c435d610389bda4676a1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 12:05:22 +0200 Subject: [PATCH 11/13] add docs --- custom/conf/app.example.ini | 11 ++++++++--- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 33ff7a62c56b..e3c2b4d30ce3 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1029,11 +1029,16 @@ PATH = ;; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`. ;THEMES = gitea,arc-green ;; -;;All available reactions users can choose on issues/prs and comments. -;;Values can be emoji alias (:smile:) or a unicode emoji. -;;For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png +;; All available reactions users can choose on issues/prs and comments. +;; Values can be emoji alias (:smile:) or a unicode emoji. +;; For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png ;REACTIONS = +1, -1, laugh, hooray, confused, heart, rocket, eyes ;; +;; Additional Emojis, who are not defined in the utf8 standart +;; By default we support gitea (:gitea:), to add more copy them to public/emoji/img/emoji_name.png and add it to this config. +;; Dont mistake it for Reactions. +;CUSTOM_EMOJIS = gitea +;; ;; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. ;DEFAULT_SHOW_FULL_NAME = false ;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index d1d47bc89301..5f305ac007ce 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -181,6 +181,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `REACTIONS`: All available reactions users can choose on issues/prs and comments Values can be emoji alias (:smile:) or a unicode emoji. For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png +- `CUSTOM_EMOJIS`: **gitea**: Additional Emojis, who are not defined in the utf8 standart. + By default we support gitea (:gitea:), to add more copy them to public/emoji/img/emoji_name.png and + add it to this config. Dont mistake it for Reactions. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets. From cb774d5450012c9d49d9b66a2aacf40c1dfe806b Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 12:26:09 +0200 Subject: [PATCH 12/13] Apply suggestions from code review Co-authored-by: zeripath --- custom/conf/app.example.ini | 2 +- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index e3c2b4d30ce3..7cae16cd79ab 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1034,7 +1034,7 @@ PATH = ;; For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png ;REACTIONS = +1, -1, laugh, hooray, confused, heart, rocket, eyes ;; -;; Additional Emojis, who are not defined in the utf8 standart +;; Additional Emojis not defined in the utf8 standard ;; By default we support gitea (:gitea:), to add more copy them to public/emoji/img/emoji_name.png and add it to this config. ;; Dont mistake it for Reactions. ;CUSTOM_EMOJIS = gitea diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 5f305ac007ce..dc3b36cb4fc1 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -181,9 +181,9 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `REACTIONS`: All available reactions users can choose on issues/prs and comments Values can be emoji alias (:smile:) or a unicode emoji. For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png -- `CUSTOM_EMOJIS`: **gitea**: Additional Emojis, who are not defined in the utf8 standart. +- `CUSTOM_EMOJIS`: **gitea**: Additional Emojis not defined in the utf8 standard. By default we support gitea (:gitea:), to add more copy them to public/emoji/img/emoji_name.png and - add it to this config. Dont mistake it for Reactions. + add it to this config. - `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used. - `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page. - `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets. From 38dd164069151101a1cc4124ba4e7e30e3be3046 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Jun 2021 15:32:35 +0200 Subject: [PATCH 13/13] dont need to escape ":" in regex --- modules/markup/html.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/markup/html.go b/modules/markup/html.go index 3e9d22438a6f..1e55629ab5dd 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -65,7 +65,7 @@ var ( blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`) // EmojiShortCodeRegex find emoji by alias like :smile: - EmojiShortCodeRegex = regexp.MustCompile(`\:[\w\+\-]+\:`) + EmojiShortCodeRegex = regexp.MustCompile(`:[\w\+\-]+:`) ) // CSS class for action keywords (e.g. "closes: #1")