Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jun 1, 2021
1 parent 6f991de commit 3c82f01
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
5 changes: 2 additions & 3 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions modules/markup/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func TestRender_emoji(t *testing.T) {
test(
":gitea:",
`<p><span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span></p>`)
test(
":custom-emoji:",
`<p>:custom-emoji:</p>`)
setting.UI.CustomEmojis = append(setting.UI.CustomEmojis, "custom-emoji")
test(
":custom-emoji:",
`<p><span class="emoji" aria-label="custom-emoji"><img alt=":custom-emoji:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/custom-emoji.png"/></span></p>`)

test(
"Some text with 😄 in the middle",
Expand Down
4 changes: 3 additions & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/structs/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
8 changes: 5 additions & 3 deletions web_src/js/features/emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = `<img alt=":${name}:" src="${AssetUrlPrefix}/img/emoji/gitea.png">`;
// TODO: use setting.UI.CustomEmojis
if (name === 'gitea' || name === 'codeberg') {
inner = `<img alt=":${name}:" src="${AssetUrlPrefix}/img/emoji/${name}.png">`;
} else {
inner = emojiString(name);
}
Expand Down

0 comments on commit 3c82f01

Please sign in to comment.