summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webapp/package.json3
-rw-r--r--webapp/utils/text_formatting.jsx15
2 files changed, 8 insertions, 10 deletions
diff --git a/webapp/package.json b/webapp/package.json
index d68223408..dce79447a 100644
--- a/webapp/package.json
+++ b/webapp/package.json
@@ -31,7 +31,8 @@
"react-textarea-autosize": "4.0.3",
"superagent": "2.1.0",
"twemoji": "2.0.5",
- "velocity-animate": "1.2.3"
+ "velocity-animate": "1.2.3",
+ "xregexp": "3.1.1"
},
"devDependencies": {
"babel-core": "6.13.2",
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 = [];