mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 07:52:19 +08:00
FEATURE: Add support for inline emoji translation.
This commit is contained in:
parent
0c88052641
commit
e9bbdef156
|
@ -57,7 +57,7 @@ function imageFor(code, opts) {
|
|||
}
|
||||
}
|
||||
|
||||
function getEmojiName(content, pos, state) {
|
||||
function getEmojiName(content, pos, state, inlineEmoji) {
|
||||
if (content.charCodeAt(pos) !== 58) {
|
||||
return;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ function getEmojiName(content, pos, state) {
|
|||
if (pos > 0) {
|
||||
let prev = content.charCodeAt(pos - 1);
|
||||
if (
|
||||
!inlineEmoji &&
|
||||
!state.md.utils.isSpace(prev) &&
|
||||
!state.md.utils.isPunctChar(String.fromCharCode(prev))
|
||||
) {
|
||||
|
@ -173,7 +174,13 @@ function getEmojiTokenByTranslation(content, pos, state) {
|
|||
}
|
||||
}
|
||||
|
||||
function applyEmoji(content, state, emojiUnicodeReplacer, enableShortcuts) {
|
||||
function applyEmoji(
|
||||
content,
|
||||
state,
|
||||
emojiUnicodeReplacer,
|
||||
enableShortcuts,
|
||||
inlineEmoji
|
||||
) {
|
||||
let i;
|
||||
let result = null;
|
||||
let contentToken = null;
|
||||
|
@ -188,7 +195,7 @@ function applyEmoji(content, state, emojiUnicodeReplacer, enableShortcuts) {
|
|||
|
||||
for (i = 0; i < content.length - 1; i++) {
|
||||
let offset = 0;
|
||||
let emojiName = getEmojiName(content, i, state);
|
||||
let emojiName = getEmojiName(content, i, state, inlineEmoji);
|
||||
let token = null;
|
||||
|
||||
if (emojiName) {
|
||||
|
@ -235,6 +242,7 @@ export function setup(helper) {
|
|||
helper.registerOptions((opts, siteSettings, state) => {
|
||||
opts.features.emoji = !!siteSettings.enable_emoji;
|
||||
opts.features.emojiShortcuts = !!siteSettings.enable_emoji_shortcuts;
|
||||
opts.features.inlineEmoji = !!siteSettings.enable_inline_emoji_translation;
|
||||
opts.emojiSet = siteSettings.emoji_set || "";
|
||||
opts.customEmoji = state.customEmoji;
|
||||
});
|
||||
|
@ -246,7 +254,8 @@ export function setup(helper) {
|
|||
c,
|
||||
s,
|
||||
md.options.discourse.emojiUnicodeReplacer,
|
||||
md.options.discourse.features.emojiShortcuts
|
||||
md.options.discourse.features.emojiShortcuts,
|
||||
md.options.discourse.features.inlineEmoji
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -1780,6 +1780,7 @@ en:
|
|||
enable_emoji_shortcuts: "Common smiley text such as :) :p :( will be converted to emojis"
|
||||
emoji_set: "How would you like your emoji?"
|
||||
emoji_autocomplete_min_chars: "Minimum number of characters required to trigger autocomplete emoji popup"
|
||||
enable_inline_emoji_translation: "Enables translation for inline emojis (without any space or punctuation before)"
|
||||
|
||||
approve_post_count: "The amount of posts from a new or basic user that must be approved"
|
||||
approve_unless_trust_level: "Posts for users below this trust level must be approved"
|
||||
|
|
|
@ -746,6 +746,14 @@ posting:
|
|||
default: 0
|
||||
locale_default:
|
||||
fr: 1
|
||||
enable_inline_emoji_translation:
|
||||
client: true
|
||||
default: false
|
||||
locale_default:
|
||||
zh_CN: true
|
||||
zh_TW: true
|
||||
ja: true
|
||||
ko: true
|
||||
approve_post_count:
|
||||
default: 0
|
||||
approve_unless_trust_level:
|
||||
|
|
|
@ -1354,6 +1354,20 @@ QUnit.test("emoji", assert => {
|
|||
);
|
||||
});
|
||||
|
||||
QUnit.test("emoji - enable_inline_emoji_translation", assert => {
|
||||
assert.cookedOptions(
|
||||
"test:smile:test",
|
||||
{ siteSettings: { enable_inline_emoji_translation: false } },
|
||||
`<p>test:smile:test</p>`
|
||||
);
|
||||
|
||||
assert.cookedOptions(
|
||||
"test:smile:test",
|
||||
{ siteSettings: { enable_inline_emoji_translation: true } },
|
||||
`<p>test<img src="/images/emoji/twitter/smile.png?v=${v}" title=":smile:" class="emoji" alt=":smile:">test</p>`
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("emoji - emojiSet", assert => {
|
||||
assert.cookedOptions(
|
||||
":smile:",
|
||||
|
|
Loading…
Reference in New Issue
Block a user