Skip to content

Commit 3c82f01

Browse files
committed
WIP
1 parent 6f991de commit 3c82f01

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

modules/markup/html.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var (
6666
blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`)
6767

6868
// EmojiShortCodeRegex find emoji by alias like :smile:
69-
EmojiShortCodeRegex = regexp.MustCompile(`\:[\w\+\-]+\:{1}`)
69+
EmojiShortCodeRegex = regexp.MustCompile(`\:[\w\+\-]+\:`)
7070
)
7171

7272
// CSS class for action keywords (e.g. "closes: #1")
@@ -916,8 +916,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
916916
converted := emoji.FromAlias(alias)
917917
if converted == nil {
918918
// check if this is a custom reaction
919-
s := strings.Join(setting.UI.Reactions, " ") + "gitea" + "codeberg"
920-
if strings.Contains(s, alias) {
919+
if util.ExistsInSlice(alias, setting.UI.CustomEmojis) {
921920
replaceContent(node, m[0], m[1], createCustomEmoji(alias, "emoji"))
922921
return
923922
}

modules/markup/html_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ func TestRender_emoji(t *testing.T) {
284284
test(
285285
":gitea:",
286286
`<p><span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span></p>`)
287+
test(
288+
":custom-emoji:",
289+
`<p>:custom-emoji:</p>`)
290+
setting.UI.CustomEmojis = append(setting.UI.CustomEmojis, "custom-emoji")
291+
test(
292+
":custom-emoji:",
293+
`<p><span class="emoji" aria-label="custom-emoji"><img alt=":custom-emoji:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/custom-emoji.png"/></span></p>`)
287294

288295
test(
289296
"Some text with 😄 in the middle",

modules/setting/setting.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ var (
198198
DefaultTheme string
199199
Themes []string
200200
Reactions []string
201-
ReactionsMap map[string]bool
201+
ReactionsMap map[string]bool `ini:"-"`
202+
CustomEmojis []string
202203
SearchRepoDescription bool
203204
UseServiceWorker bool
204205

@@ -246,6 +247,7 @@ var (
246247
DefaultTheme: `gitea`,
247248
Themes: []string{`gitea`, `arc-green`},
248249
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
250+
CustomEmojis: []string{`gitea`, `codeberg`},
249251
Notification: struct {
250252
MinTimeout time.Duration
251253
TimeoutStep time.Duration

modules/structs/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type GeneralRepoSettings struct {
1818
type GeneralUISettings struct {
1919
DefaultTheme string `json:"default_theme"`
2020
AllowedReactions []string `json:"allowed_reactions"`
21+
CustomEmojis []string `json:"custom_emojis"`
2122
}
2223

2324
// GeneralAPISettings contains global api settings exposed by it

routers/api/v1/settings/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func GetGeneralUISettings(ctx *context.APIContext) {
2525
ctx.JSON(http.StatusOK, api.GeneralUISettings{
2626
DefaultTheme: setting.UI.DefaultTheme,
2727
AllowedReactions: setting.UI.Reactions,
28+
CustomEmojis: setting.UI.CustomEmojis,
2829
})
2930
}
3031

web_src/js/features/emoji.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import emojis from '../../../assets/emoji.json';
22

33
const {AssetUrlPrefix} = window.config;
44

5-
const tempMap = {gitea: ':gitea:'};
5+
// TODO: use setting.UI.CustomEmojis
6+
const tempMap = {gitea: ':gitea:', codeberg: ':codeberg:'};
67
for (const {emoji, aliases} of emojis) {
78
for (const alias of aliases || []) {
89
tempMap[alias] = emoji;
@@ -23,8 +24,9 @@ for (const key of emojiKeys) {
2324
// retrieve HTML for given emoji name
2425
export function emojiHTML(name) {
2526
let inner;
26-
if (name === 'gitea') {
27-
inner = `<img alt=":${name}:" src="${AssetUrlPrefix}/img/emoji/gitea.png">`;
27+
// TODO: use setting.UI.CustomEmojis
28+
if (name === 'gitea' || name === 'codeberg') {
29+
inner = `<img alt=":${name}:" src="${AssetUrlPrefix}/img/emoji/${name}.png">`;
2830
} else {
2931
inner = emojiString(name);
3032
}

0 commit comments

Comments
 (0)