A platform for community discussion. Free, open, simple.
FEATURE: allow site operators to disable emoji shortcuts
Sam3492a9105671
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6index 522edbe7669..dd45e3f54c7 100644--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6@@ -170,7 +170,7 @@ function getEmojiTokenByTranslation(content, pos, state) {}}-function applyEmoji(content, state, emojiUnicodeReplacer) {+function applyEmoji(content, state, emojiUnicodeReplacer, enableShortcuts) {let i;let result = null;let contentToken = null;@@ -195,7 +195,7 @@ function applyEmoji(content, state, emojiUnicodeReplacer) {}}- if (!token) {+ if (enableShortcuts && !token) {// handle aliases (note: we can't do this in inline cause ; is not a split point)//let info = getEmojiTokenByTranslation(content, i, state);@@ -231,13 +231,19 @@ function applyEmoji(content, state, emojiUnicodeReplacer) {export function setup(helper) {helper.registerOptions((opts, siteSettings, state)=>{opts.features.emoji = !!siteSettings.enable_emoji;+ opts.features.emojiShortcuts = !!siteSettings.enable_emoji_shortcuts;opts.emojiSet = siteSettings.emoji_set || "";opts.customEmoji = state.customEmoji;});helper.registerPlugin((md)=>{md.core.ruler.push('emoji', state => md.options.discourse.helpers.textReplace(- state, (c,s)=>applyEmoji(c,s,md.options.discourse.emojiUnicodeReplacer))+ state, (c,s)=>applyEmoji(+ c,+ s,+ md.options.discourse.emojiUnicodeReplacer,+ md.options.discourse.features.emojiShortcuts+ )));});diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 84d12f05b5d..33021688e57 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1524,6 +1524,7 @@ en:slug_generation_method: "Choose a slug generation method. 'encoded' will generate percent encoding string. 'none' will disable slug at all."enable_emoji: "Enable emoji"+ enable_emoji_shortcuts: "Common smiley text such as :) :p :( will be converted to emojis"emoji_set: "How would you like your emoji?"enforce_square_emoji: "Force a square aspect ratio to all emojis."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex dcdc6caa5f6..fe2c4415dff 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -601,6 +601,9 @@ posting:enable_emoji:default: trueclient: true+ enable_emoji_shortcuts:+ default: true+ client: trueemoji_set:default: 'twitter'client: truediff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rbindex d02683bee8c..918056cc42f 100644--- a/spec/components/pretty_text_spec.rb+++ b/spec/components/pretty_text_spec.rb@@ -746,6 +746,20 @@ describe PrettyText doexpect(PrettyText.cook("π£")).not_to match(/\:bomb\:/)end+ it "doesn't replace emoji if emoji is disabled" do+ SiteSetting.enable_emoji = false+ expect(PrettyText.cook(":bomb:")).to eq("<p>:bomb:</p>")+ end++ it "doesn't replace shortcuts if disabled" do+ SiteSetting.enable_emoji_shortcuts = false+ expect(PrettyText.cook(":)")).to eq("<p>:)</p>")+ end++ it "does replace shortcuts if enabled" do+ expect(PrettyText.cook(":)")).to match("smile")+ end+it "replaces skin toned emoji" doexpect(PrettyText.cook("hello π±πΏββοΈ")).to eq("<p>hello <img src=\"/images/emoji/twitter/blonde_woman/6.png?v=5\" title=\":blonde_woman:t6:\" class=\"emoji\" alt=\":blonde_woman:t6:\"></p>")expect(PrettyText.cook("hello π©βπ€")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_singer.png?v=5\" title=\":woman_singer:\" class=\"emoji\" alt=\":woman_singer:\"></p>")