summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElias Nahum <nahumhbl@gmail.com>2016-03-31 18:16:55 -0300
committerElias Nahum <nahumhbl@gmail.com>2016-03-31 20:13:18 -0300
commitff01fc7337eedc51c84610a8c6bf578e4f42b9df (patch)
tree4fb4be518eb93767d3a9b12b60388eb239b0f889
parent36f611fac48536f26770357de8d5b6767bd46d2f (diff)
downloadchat-ff01fc7337eedc51c84610a8c6bf578e4f42b9df.tar.gz
chat-ff01fc7337eedc51c84610a8c6bf578e4f42b9df.tar.bz2
chat-ff01fc7337eedc51c84610a8c6bf578e4f42b9df.zip
Replace Autolinker in extractLinks with a pattern
-rw-r--r--webapp/utils/utils.jsx37
1 files changed, 6 insertions, 31 deletions
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index b248368fc..9af36f9dd 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -14,7 +14,6 @@ var ActionTypes = Constants.ActionTypes;
import * as Client from './client.jsx';
import * as AsyncClient from './async_client.jsx';
import * as client from './client.jsx';
-import Autolinker from 'autolinker';
import React from 'react';
import {browserHistory} from 'react-router';
@@ -315,13 +314,8 @@ export function getTimestamp() {
// extracts links not styled by Markdown
export function extractLinks(text) {
- text; // eslint-disable-line no-unused-expressions
- Autolinker; // eslint-disable-line no-unused-expressions
-
- // skip this operation because autolinker is having issues
- return [];
-
- /*const links = [];
+ const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
+ let links;
let inText = text;
// strip out code blocks
@@ -330,32 +324,13 @@ export function extractLinks(text) {
// strip out inline markdown images
inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, '');
- function replaceFn(autolinker, match) {
- let link = '';
- const matchText = match.getMatchedText();
-
- if (matchText.trim().indexOf('http') === 0) {
- link = matchText;
- } else {
- link = 'http://' + matchText;
- }
-
- links.push(link);
- }
+ links = inText.match(pattern) || [];
- Autolinker.link(
- inText,
- {
- replaceFn,
- urls: {schemeMatches: true, wwwMatches: true, tldMatches: false},
- emails: false,
- twitter: false,
- phone: false,
- hashtag: false
+ return links.map(
+ (url) => {
+ return url.trim();
}
);
-
- return links;*/
}
export function escapeRegExp(string) {