mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
implement unicode emoji replacements
This commit is contained in:
@@ -3,7 +3,28 @@ __buildOptions = require('pretty-text/pretty-text').buildOptions;
|
||||
__performEmojiUnescape = require('pretty-text/emoji').performEmojiUnescape;
|
||||
|
||||
__utils = require('discourse/lib/utilities');
|
||||
__setUnicode = require('pretty-text/engines/discourse-markdown/emoji').setUnicodeReplacements;
|
||||
|
||||
__emojiUnicodeReplacer = null;
|
||||
|
||||
__setUnicode = function(replacements) {
|
||||
require('pretty-text/engines/discourse-markdown/emoji').setUnicodeReplacements(replacements);
|
||||
|
||||
let unicodeRegexp = new RegExp(Object.keys(replacements).sort().reverse().join("|"), "g");
|
||||
|
||||
__emojiUnicodeReplacer = function(text) {
|
||||
unicodeRegexp.lastIndex = 0;
|
||||
let m;
|
||||
while ((m = unicodeRegexp.exec(text)) !== null) {
|
||||
let replacement = ":" + replacements[m[0]] + ":";
|
||||
const before = text.charAt(m.index-1);
|
||||
if (!/\B/.test(before)) {
|
||||
replacement = "\u200b" + replacement;
|
||||
}
|
||||
text = text.replace(m[0], replacement);
|
||||
}
|
||||
return text;
|
||||
};
|
||||
};
|
||||
|
||||
__paths = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user