Switch back to upstream autolinker

This commit is contained in:
Ken-Håvard Lieng 2017-04-16 06:08:45 +02:00
parent e294e109f8
commit 305c1fa08f
4 changed files with 59 additions and 38 deletions

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@
"webpack-hot-middleware": "^2.17.0" "webpack-hot-middleware": "^2.17.0"
}, },
"dependencies": { "dependencies": {
"autolinker": "git+https://github.com/robbie-c/Autolinker.js.git", "autolinker": "^1.4.3",
"backo": "^1.1.0", "backo": "^1.1.0",
"base64-arraybuffer": "^0.1.5", "base64-arraybuffer": "^0.1.5",
"history": "^4.5.1", "history": "^4.5.1",

View File

@ -3,17 +3,38 @@ import React from 'react';
const autolinker = new Autolinker({ const autolinker = new Autolinker({
stripPrefix: false, stripPrefix: false,
doJoin: false, stripTrailingSlash: false
replaceFn: (linker, match) => {
if (match.getType() === 'url') {
return <a target="_blank" rel="noopener noreferrer" href={match.getAnchorHref()}>{match.getAnchorText()}</a>;
}
return null;
},
React
}); });
export default function linkify(text) { export default function linkify(text) {
return autolinker.link(text); const matches = autolinker.parseText(text);
const result = [];
let pos = 0;
for (let i = 0; i < matches.length; i++) {
const match = matches[i];
if (match.offset > pos) {
result.push(text.slice(pos, match.offset));
pos = match.offset;
}
if (match.getType() === 'url') {
result.push(
<a target="_blank" rel="noopener noreferrer" href={match.getAnchorHref()}>
{match.matchedText}
</a>
);
} else {
result.push(match.matchedText);
}
pos += match.matchedText.length;
}
if (pos < text.length) {
result.push(text.slice(pos));
}
return result;
} }

View File

@ -205,9 +205,9 @@ asynckit@^0.4.0:
version "0.4.0" version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
"autolinker@git+https://github.com/robbie-c/Autolinker.js.git": autolinker@^1.4.3:
version "0.22.0" version "1.4.3"
resolved "git+https://github.com/robbie-c/Autolinker.js.git#7078b4e408df7f4f4dc09c378859bdc5d6b9d36a" resolved "https://registry.yarnpkg.com/autolinker/-/autolinker-1.4.3.tgz#2e615057c8e371399a6d77949a9a6af24fe46dfc"
autoprefixer@^6.0.0, autoprefixer@^6.3.1: autoprefixer@^6.0.0, autoprefixer@^6.3.1:
version "6.7.7" version "6.7.7"
@ -4482,14 +4482,14 @@ sax@~1.2.1:
version "1.2.2" version "1.2.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"
"semver@2 || 3 || 4 || 5", semver@^4.1.0: "semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"
semver@^5.3.0:
version "5.3.0" version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
semver@^4.1.0:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"
send@0.15.1: send@0.15.1:
version "0.15.1" version "0.15.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.15.1.tgz#8a02354c26e6f5cca700065f5f0cdeba90ec7b5f" resolved "https://registry.yarnpkg.com/send/-/send-0.15.1.tgz#8a02354c26e6f5cca700065f5f0cdeba90ec7b5f"