Changed emoticons so that they much be surrounded by whitespace

Этот коммит содержится в:
hmhealey
2015-10-08 12:36:01 -04:00
родитель c25d2d1e99
Коммит 5bcba280c6

Просмотреть файл

@@ -2,26 +2,26 @@
// See License.txt for license information. // See License.txt for license information.
const emoticonPatterns = { const emoticonPatterns = {
smile: /:-?\)/g, // :) smile: /(^|\s)(:-?\))($|\s)/g, // :)
open_mouth: /:o/gi, // :o open_mouth: /(^|\s)(:o)($|\s)/gi, // :o
scream: /:-o/gi, // :-o scream: /(^|\s)(:-o)($|\s)/gi, // :-o
smirk: /:-?]/g, // :] smirk: /(^|\s)(:-?])($|\s)/g, // :]
grinning: /:-?d/gi, // :D grinning: /(^|\s)(:-?d)($|\s)/gi, // :D
stuck_out_tongue_closed_eyes: /x-d/gi, // x-d stuck_out_tongue_closed_eyes: /(^|\s)(x-d)($|\s)/gi, // x-d
stuck_out_tongue: /:-?p/gi, // :p stuck_out_tongue: /(^|\s)(:-?p)($|\s)/gi, // :p
rage: /:-?[\[@]/g, // :@ rage: /(^|\s)(:-?[\[@])($|\s)/g, // :@
frowning: /:-?\(/g, // :( frowning: /(^|\s)(:-?\()($|\s)/g, // :(
sob: /:[']-?\(|:'\(/g, // :`( sob: /(^|\s)(:[']-?\(|:'\()($|\s)/g, // :`(
kissing_heart: /:-?\*/g, // :* kissing_heart: /(^|\s)(:-?\*)($|\s)/g, // :*
pensive: /:-?\//g, // :/ pensive: /(^|\s)(:-?\/)($|\s)/g, // :/
confounded: /:-?s/gi, // :s confounded: /(^|\s)(:-?s)($|\s)/gi, // :s
flushed: /:-?\|/g, // :| flushed: /(^|\s)(:-?\|)($|\s)/g, // :|
relaxed: /:-?\$/g, // :$ relaxed: /(^|\s)(:-?\$)($|\s)/g, // :$
mask: /:-x/gi, // :-x mask: /(^|\s)(:-x)($|\s)/gi, // :-x
heart: /<3|&lt;3/g, // <3 heart: /(^|\s)(<3|&lt;3)($|\s)/g, // <3
broken_heart: /<\/3|&lt;&#x2F;3/g, // </3 broken_heart: /(^|\s)(<\/3|&lt;&#x2F;3)($|\s)/g, // </3
thumbsup: /:\+1:/g, // :+1: thumbsup: /(^|\s)(:\+1:)($|\s)/g, // :+1:
thumbsdown: /:\-1:/g // :-1: thumbsdown: /(^|\s)(:\-1:)($|\s)/g // :-1:
}; };
function initializeEmoticonMap() { function initializeEmoticonMap() {
@@ -126,7 +126,7 @@ const emoticonMap = initializeEmoticonMap();
export function handleEmoticons(text, tokens) { export function handleEmoticons(text, tokens) {
let output = text; let output = text;
function replaceEmoticonWithToken(match, name) { function replaceEmoticonWithToken(match, prefix, name, suffix) {
if (emoticonMap[name]) { if (emoticonMap[name]) {
const index = tokens.size; const index = tokens.size;
const alias = `MM_EMOTICON${index}`; const alias = `MM_EMOTICON${index}`;
@@ -136,18 +136,18 @@ export function handleEmoticons(text, tokens) {
originalText: match originalText: match
}); });
return alias; return prefix + alias + suffix;
} }
return match; return match;
} }
output = output.replace(/:([a-zA-Z0-9_-]+):/g, replaceEmoticonWithToken); output = output.replace(/(^|\s):([a-zA-Z0-9_-]+):($|\s)/g, replaceEmoticonWithToken);
$.each(emoticonPatterns, (name, pattern) => { $.each(emoticonPatterns, (name, pattern) => {
// this might look a bit funny, but since the name isn't contained in the actual match // this might look a bit funny, but since the name isn't contained in the actual match
// like with the named emoticons, we need to add it in manually // like with the named emoticons, we need to add it in manually
output = output.replace(pattern, (match) => replaceEmoticonWithToken(match, name)); output = output.replace(pattern, (match, prefix, emoticon, suffix) => replaceEmoticonWithToken(match, prefix, name, suffix));
}); });
return output; return output;