summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2016-04-01 15:05:54 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2016-04-01 15:05:54 -0400
commita427d61b33fa0e3926c61bab456feb907a89af59 (patch)
treeb6b5901fa739971020d4662d7de27d8b9c78de5f
parentd9d6a0c7837d585297047e2a606ef20c86bfdfc2 (diff)
parent9ec459526a2bf4d119ab779473c9606c524b6131 (diff)
downloadchat-a427d61b33fa0e3926c61bab456feb907a89af59.tar.gz
chat-a427d61b33fa0e3926c61bab456feb907a89af59.tar.bz2
chat-a427d61b33fa0e3926c61bab456feb907a89af59.zip
Merge pull request #2602 from ZBoxApp/autolinker
Replace Autolinker in extractLinks with a pattern
-rw-r--r--webapp/components/post_body_additional_content.jsx2
-rw-r--r--webapp/utils/utils.jsx39
2 files changed, 7 insertions, 34 deletions
diff --git a/webapp/components/post_body_additional_content.jsx b/webapp/components/post_body_additional_content.jsx
index 2cd82f213..452597dde 100644
--- a/webapp/components/post_body_additional_content.jsx
+++ b/webapp/components/post_body_additional_content.jsx
@@ -70,7 +70,7 @@ export default class PostBodyAdditionalContent extends React.Component {
return this.getSlackAttachment();
}
- const link = Utils.extractLinks(this.props.post.message)[0];
+ const link = Utils.extractFirstLink(this.props.post.message);
if (!link) {
return null;
}
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index b248368fc..dc9291ab7 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';
@@ -314,14 +313,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 = [];
+export function extractFirstLink(text) {
+ const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/i;
let inText = text;
// strip out code blocks
@@ -330,32 +323,12 @@ 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);
+ const match = pattern.exec(inText);
+ if (match) {
+ return match[0].trim();
}
- Autolinker.link(
- inText,
- {
- replaceFn,
- urls: {schemeMatches: true, wwwMatches: true, tldMatches: false},
- emails: false,
- twitter: false,
- phone: false,
- hashtag: false
- }
- );
-
- return links;*/
+ return '';
}
export function escapeRegExp(string) {