diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-05-16 15:54:24 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-16 15:54:24 -0400 |
commit | 1b9deb43925393a52b03cd43bb733e9e602c1483 (patch) | |
tree | 74b2e780692838cdd6540493c7c694c954bd3f60 /webapp/utils/emoticons.jsx | |
parent | 1f609e9cf799ddb6bedd5fe3c0eeb36b92ed243d (diff) | |
download | chat-1b9deb43925393a52b03cd43bb733e9e602c1483.tar.gz chat-1b9deb43925393a52b03cd43bb733e9e602c1483.tar.bz2 chat-1b9deb43925393a52b03cd43bb733e9e602c1483.zip |
Changed named emoticons to not require surrounding whitespace and added unit tests (#3009)
Diffstat (limited to 'webapp/utils/emoticons.jsx')
-rw-r--r-- | webapp/utils/emoticons.jsx | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/webapp/utils/emoticons.jsx b/webapp/utils/emoticons.jsx index 505e10c19..35c7dba04 100644 --- a/webapp/utils/emoticons.jsx +++ b/webapp/utils/emoticons.jsx @@ -1,8 +1,6 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import $ from 'jquery'; - import Constants from './constants.jsx'; import emojis from './emoji.json'; @@ -134,7 +132,7 @@ export function getEmoticonsByCodePoint() { export function handleEmoticons(text, tokens) { let output = text; - function replaceEmoticonWithToken(fullMatch, prefix, matchText, name) { + function replaceEmoticonWithToken(fullMatch, matchText, name) { if (getEmoticonsByName().has(name)) { const index = tokens.size; const alias = `MM_EMOTICON${index}`; @@ -145,19 +143,23 @@ export function handleEmoticons(text, tokens) { originalText: fullMatch }); - return prefix + alias; + return alias; } return fullMatch; } - output = output.replace(/(^|\s)(:([a-zA-Z0-9_-]+):)(?=$|\s)/g, (fullMatch, prefix, matchText, name) => replaceEmoticonWithToken(fullMatch, prefix, matchText, name)); + // match named emoticons like :goat: + output = output.replace(/(:([a-zA-Z0-9_-]+):)/g, (fullMatch, matchText, name) => replaceEmoticonWithToken(fullMatch, matchText, name)); + + // match text smilies like :D + for (const name of Object.keys(emoticonPatterns)) { + const pattern = emoticonPatterns[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, (fullMatch, prefix, matchText) => replaceEmoticonWithToken(fullMatch, prefix, matchText, name)); - }); + output = output.replace(pattern, (fullMatch, matchText) => replaceEmoticonWithToken(fullMatch, matchText, name)); + } return output; } |