Merge pull request #2602 from ZBoxApp/autolinker

Replace Autolinker in extractLinks with a pattern
Этот коммит содержится в:
Harrison Healey
2016-04-01 15:05:54 -04:00
родитель d9d6a0c783 9ec459526a
Коммит a427d61b33
2 изменённых файлов: 7 добавлений и 34 удалений

Просмотреть файл

@@ -70,7 +70,7 @@ export default class PostBodyAdditionalContent extends React.Component {
return this.getSlackAttachment(); return this.getSlackAttachment();
} }
const link = Utils.extractLinks(this.props.post.message)[0]; const link = Utils.extractFirstLink(this.props.post.message);
if (!link) { if (!link) {
return null; return null;
} }

Просмотреть файл

@@ -14,7 +14,6 @@ var ActionTypes = Constants.ActionTypes;
import * as Client from './client.jsx'; import * as Client from './client.jsx';
import * as AsyncClient from './async_client.jsx'; import * as AsyncClient from './async_client.jsx';
import * as client from './client.jsx'; import * as client from './client.jsx';
import Autolinker from 'autolinker';
import React from 'react'; import React from 'react';
import {browserHistory} from 'react-router'; import {browserHistory} from 'react-router';
@@ -314,14 +313,8 @@ export function getTimestamp() {
} }
// extracts links not styled by Markdown // extracts links not styled by Markdown
export function extractLinks(text) { export function extractFirstLink(text) {
text; // eslint-disable-line no-unused-expressions const pattern = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/i;
Autolinker; // eslint-disable-line no-unused-expressions
// skip this operation because autolinker is having issues
return [];
/*const links = [];
let inText = text; let inText = text;
// strip out code blocks // strip out code blocks
@@ -330,32 +323,12 @@ export function extractLinks(text) {
// strip out inline markdown images // strip out inline markdown images
inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, ''); inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, '');
function replaceFn(autolinker, match) { const match = pattern.exec(inText);
let link = ''; if (match) {
const matchText = match.getMatchedText(); return match[0].trim();
if (matchText.trim().indexOf('http') === 0) {
link = matchText;
} else {
link = 'http://' + matchText;
}
links.push(link);
} }
Autolinker.link( return '';
inText,
{
replaceFn,
urls: {schemeMatches: true, wwwMatches: true, tldMatches: false},
emails: false,
twitter: false,
phone: false,
hashtag: false
}
);
return links;*/
} }
export function escapeRegExp(string) { export function escapeRegExp(string) {