summaryrefslogtreecommitdiffstats
path: root/webapp/utils/text_formatting.jsx
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-08-12 07:49:19 -0400
committerJoram Wilander <jwawilander@gmail.com>2016-08-12 07:49:19 -0400
commitc0a905c0376014763f851405032d2ae5440b45da (patch)
treedc6ad11a67843fd0020083b9ed841d2c8704f04a /webapp/utils/text_formatting.jsx
parent96420542b193defc6a562d2151acf113ef93b87f (diff)
downloadchat-c0a905c0376014763f851405032d2ae5440b45da.tar.gz
chat-c0a905c0376014763f851405032d2ae5440b45da.tar.bz2
chat-c0a905c0376014763f851405032d2ae5440b45da.zip
PLT-1424 Added XRegExp library to fix search highlighting (#3787)
Diffstat (limited to 'webapp/utils/text_formatting.jsx')
-rw-r--r--webapp/utils/text_formatting.jsx15
1 files changed, 6 insertions, 9 deletions
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 655b4180e..c110fc52f 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -11,6 +11,7 @@ import PreferenceStore from 'stores/preference_store.jsx';
import UserStore from 'stores/user_store.jsx';
import twemoji from 'twemoji';
import * as Utils from './utils.jsx';
+import XRegExp from 'xregexp';
// pattern to detect the existance of a Chinese, Japanese, or Korean character in a string
// http://stackoverflow.com/questions/15033196/using-javascript-to-check-whether-a-string-contains-japanese-characters-includi
@@ -140,13 +141,9 @@ function autolinkEmails(text, tokens) {
return autolinker.link(text);
}
-function autolinkAtMentions(text, tokens) {
- // Return true if provided character is punctuation
- function isPunctuation(character) {
- const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g;
- return re.test(character);
- }
+const punctuation = XRegExp.cache('[^\\pL\\d]');
+function autolinkAtMentions(text, tokens) {
// Test if provided text needs to be highlighted, special mention or current user
function mentionExists(u) {
return (Constants.SPECIAL_MENTIONS.indexOf(u) !== -1 || UserStore.getProfileByUsername(u));
@@ -176,7 +173,7 @@ function autolinkAtMentions(text, tokens) {
const originalUsername = usernameLower;
for (let c = usernameLower.length; c > 0; c--) {
- if (isPunctuation(usernameLower[c - 1])) {
+ if (punctuation.test(usernameLower[c - 1])) {
usernameLower = usernameLower.substring(0, c - 1);
if (mentionExists(usernameLower)) {
@@ -299,8 +296,8 @@ function autolinkHashtags(text, tokens) {
return output.replace(/(^|\W)(#[a-zA-ZäöüÄÖÜß][a-zA-Z0-9äöüÄÖÜß.\-_]*)\b/g, replaceHashtagWithToken);
}
-const puncStart = /^[^a-zA-Z0-9#]+/;
-const puncEnd = /[^a-zA-Z0-9]+$/;
+const puncStart = XRegExp.cache('^[^\\pL\\d\\s#]+');
+const puncEnd = XRegExp.cache('[^\\pL\\d\\s]+$');
function parseSearchTerms(searchTerm) {
let terms = [];