summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-10-22 15:27:32 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-22 15:28:55 -0400
commit50579f71bc678d19efaf06780817d2b1905df66a (patch)
treea497bae4673e4d3fd7ccac2b0e7f458a179c6d1b /web
parent649f42e3fc706f8fa829276bcdb825381bc703f2 (diff)
downloadchat-50579f71bc678d19efaf06780817d2b1905df66a.tar.gz
chat-50579f71bc678d19efaf06780817d2b1905df66a.tar.bz2
chat-50579f71bc678d19efaf06780817d2b1905df66a.zip
Fixed handling of whitespace surrounding emoticons
Diffstat (limited to 'web')
-rw-r--r--web/react/utils/emoticons.jsx56
1 files changed, 28 insertions, 28 deletions
diff --git a/web/react/utils/emoticons.jsx b/web/react/utils/emoticons.jsx
index aabddcffd..bb948b6dc 100644
--- a/web/react/utils/emoticons.jsx
+++ b/web/react/utils/emoticons.jsx
@@ -2,27 +2,27 @@
// See License.txt for license information.
const emoticonPatterns = {
- smile: /(^|\s)(:-?\))($|\s)/g, // :)
- wink: /(^|\s)(;-?\))($|\s)/g, // ;)
- open_mouth: /(^|\s)(:o)($|\s)/gi, // :o
- scream: /(^|\s)(:-o)($|\s)/gi, // :-o
- smirk: /(^|\s)(:-?])($|\s)/g, // :]
- grinning: /(^|\s)(:-?d)($|\s)/gi, // :D
- stuck_out_tongue_closed_eyes: /(^|\s)(x-d)($|\s)/gi, // x-d
- stuck_out_tongue: /(^|\s)(:-?p)($|\s)/gi, // :p
- rage: /(^|\s)(:-?[\[@])($|\s)/g, // :@
- frowning: /(^|\s)(:-?\()($|\s)/g, // :(
- sob: /(^|\s)(:['’]-?\(|:&#x27;\(|:&#39;\()($|\s)/g, // :`(
- kissing_heart: /(^|\s)(:-?\*)($|\s)/g, // :*
- pensive: /(^|\s)(:-?\/)($|\s)/g, // :/
- confounded: /(^|\s)(:-?s)($|\s)/gi, // :s
- flushed: /(^|\s)(:-?\|)($|\s)/g, // :|
- relaxed: /(^|\s)(:-?\$)($|\s)/g, // :$
- mask: /(^|\s)(:-x)($|\s)/gi, // :-x
- heart: /(^|\s)(<3|&lt;3)($|\s)/g, // <3
- broken_heart: /(^|\s)(<\/3|&lt;&#x2F;3)($|\s)/g, // </3
- thumbsup: /(^|\s)(:\+1:)($|\s)/g, // :+1:
- thumbsdown: /(^|\s)(:\-1:)($|\s)/g // :-1:
+ smile: /(^|\s)(:-?\))(?=$|\s)/g, // :)
+ wink: /(^|\s)(;-?\))(?=$|\s)/g, // ;)
+ open_mouth: /(^|\s)(:o)(?=$|\s)/gi, // :o
+ scream: /(^|\s)(:-o)(?=$|\s)/gi, // :-o
+ smirk: /(^|\s)(:-?])(?=$|\s)/g, // :]
+ grinning: /(^|\s)(:-?d)(?=$|\s)/gi, // :D
+ stuck_out_tongue_closed_eyes: /(^|\s)(x-d)(?=$|\s)/gi, // x-d
+ stuck_out_tongue: /(^|\s)(:-?p)(?=$|\s)/gi, // :p
+ rage: /(^|\s)(:-?[\[@])(?=$|\s)/g, // :@
+ frowning: /(^|\s)(:-?\()(?=$|\s)/g, // :(
+ sob: /(^|\s)(:['’]-?\(|:&#x27;\(|:&#39;\()(?=$|\s)/g, // :`(
+ kissing_heart: /(^|\s)(:-?\*)(?=$|\s)/g, // :*
+ pensive: /(^|\s)(:-?\/)(?=$|\s)/g, // :/
+ confounded: /(^|\s)(:-?s)(?=$|\s)/gi, // :s
+ flushed: /(^|\s)(:-?\|)(?=$|\s)/g, // :|
+ relaxed: /(^|\s)(:-?\$)(?=$|\s)/g, // :$
+ mask: /(^|\s)(:-x)(?=$|\s)/gi, // :-x
+ heart: /(^|\s)(<3|&lt;3)(?=$|\s)/g, // <3
+ broken_heart: /(^|\s)(<\/3|&lt;&#x2F;3)(?=$|\s)/g, // </3
+ thumbsup: /(^|\s)(:\+1:)(?=$|\s)/g, // :+1:
+ thumbsdown: /(^|\s)(:\-1:)(?=$|\s)/g // :-1:
};
function initializeEmoticonMap() {
@@ -127,28 +127,28 @@ const emoticonMap = initializeEmoticonMap();
export function handleEmoticons(text, tokens) {
let output = text;
- function replaceEmoticonWithToken(match, prefix, name, suffix) {
+ function replaceEmoticonWithToken(fullMatch, prefix, matchText, name) {
if (emoticonMap[name]) {
const index = tokens.size;
const alias = `MM_EMOTICON${index}`;
tokens.set(alias, {
- value: `<img align="absmiddle" alt="${match}" class="emoji" src="${getImagePathForEmoticon(name)}" title="${match}" />`,
- originalText: match
+ value: `<img align="absmiddle" alt="${matchText}" class="emoji" src="${getImagePathForEmoticon(name)}" title="${matchText}" />`,
+ originalText: fullMatch
});
- return prefix + alias + suffix;
+ return prefix + alias;
}
- return match;
+ return fullMatch;
}
- output = output.replace(/(^|\s):([a-zA-Z0-9_-]+):($|\s)/g, replaceEmoticonWithToken);
+ output = output.replace(/(^|\s)(:([a-zA-Z0-9_-]+):)(?=$|\s)/g, (fullMatch, prefix, matchText, name) => replaceEmoticonWithToken(fullMatch, prefix, matchText, name));
$.each(emoticonPatterns, (name, pattern) => {
// 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
- output = output.replace(pattern, (match, prefix, emoticon, suffix) => replaceEmoticonWithToken(match, prefix, name, suffix));
+ output = output.replace(pattern, (fullMatch, prefix, matchText) => replaceEmoticonWithToken(fullMatch, prefix, matchText, name));
});
return output;