implement unicode emoji replacements
This commit is contained in:
@@ -149,6 +149,7 @@ module PrettyText
|
||||
end
|
||||
|
||||
if SiteSetting.enable_experimental_markdown_it
|
||||
# defer load markdown it
|
||||
unless context.eval("window.markdownit")
|
||||
ctx_load_manifest(context, "markdown-it-bundle.js")
|
||||
end
|
||||
@@ -168,6 +169,7 @@ module PrettyText
|
||||
__optInput.categoryHashtagLookup = __categoryLookup;
|
||||
__optInput.mentionLookup = __mentionLookup;
|
||||
__optInput.customEmoji = #{custom_emoji.to_json};
|
||||
__optInput.emojiUnicodeReplacer = __emojiUnicodeReplacer;
|
||||
JS
|
||||
|
||||
if opts[:topicId]
|
||||
|
||||
@@ -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