diff options
-rw-r--r-- | webapp/components/post_body_additional_content.jsx | 2 | ||||
-rw-r--r-- | webapp/utils/utils.jsx | 39 |
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) { |