linkifyjs
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
@@ -38,3 +38,4 @@ "use strict"; | ||
formattedHref = options.resolve(opts.formatHref, href, token.type), | ||
attributesHash = options.resolve(opts.attributes, token.type); | ||
attributesHash = options.resolve(opts.attributes, token.type), | ||
events = options.resolve(opts.events, token.type); | ||
@@ -56,2 +57,12 @@ // Build the link | ||
if (events) { | ||
for (var _event in events) { | ||
if (link.addEventListener) { | ||
link.addEventListener(_event, events[_event]); | ||
} else if (link.attachEvent) { | ||
link.attachEvent("on" + _event, events[_event]); | ||
} | ||
} | ||
} | ||
link.appendChild(doc.createTextNode(formatted)); | ||
@@ -58,0 +69,0 @@ result.push(link); |
@@ -47,12 +47,15 @@ "use strict"; | ||
$("[data-linkify]").each(function () { | ||
var $this = $(this), | ||
data = $this.data(), | ||
target = data.linkify, | ||
nl2br = data.linkifyNlbr, | ||
options = { | ||
linkAttributes: data.linkifyAttributes, | ||
defaultProtocol: data.linkifyDefaultProtocol, | ||
events: data.linkifyEvents, | ||
format: data.linkifyFormat, | ||
formatHref: data.linkifyFormatHref, | ||
newLine: data.linkifyNewline, // deprecated | ||
nl2br: !!data.linkifyNlbr, | ||
nl2br: !!nl2br && nl2br !== 0 && nl2br !== "false", | ||
tagName: data.linkifyTagname, | ||
@@ -68,3 +71,3 @@ target: data.linkifyTarget, | ||
// Apply it right away if possible | ||
if (typeof __karma__ === "undefined" && typeof jQuery !== "undefined" && doc) { | ||
if (typeof jQuery !== "undefined" && doc) { | ||
apply(jQuery, doc); | ||
@@ -71,0 +74,0 @@ } |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
/** | ||
@@ -7,2 +5,4 @@ Convert strings of text into linkable HTML text | ||
"use strict"; | ||
var _linkify = require("./linkify"); | ||
@@ -9,0 +9,0 @@ |
@@ -5,2 +5,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var options = _interopRequireWildcard(require("./linkify/utils/options")); | ||
@@ -67,5 +71,2 @@ | ||
exports.test = test; | ||
exports.tokenize = tokenize; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.tokenize = tokenize; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
@@ -286,5 +289,2 @@ Not exactly parser, more like the second-stage scanner (although we can | ||
exports.run = run; | ||
exports.start = start; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.start = start; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
@@ -187,5 +190,2 @@ The scanner provides an interface that takes a string of text as input, and | ||
exports.run = run; | ||
exports.start = start; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.start = start; |
@@ -5,6 +5,10 @@ "use strict"; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
@@ -45,3 +49,3 @@ A simple state machine that can emit token classes | ||
_prototypeProperties(BaseState, null, { | ||
_createClass(BaseState, { | ||
on: { | ||
@@ -66,5 +70,3 @@ | ||
this.j.push([symbol, state]); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -98,5 +100,3 @@ next: { | ||
return false; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -114,5 +114,3 @@ accepts: { | ||
return !!this.T; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -133,5 +131,3 @@ test: { | ||
return item === symbol; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -149,5 +145,3 @@ emit: { | ||
return this.T; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
@@ -166,14 +160,14 @@ }); | ||
var CharacterState = (function (BaseState) { | ||
var CharacterState = (function (_BaseState) { | ||
function CharacterState() { | ||
_classCallCheck(this, CharacterState); | ||
if (BaseState != null) { | ||
BaseState.apply(this, arguments); | ||
if (_BaseState != null) { | ||
_BaseState.apply(this, arguments); | ||
} | ||
} | ||
_inherits(CharacterState, BaseState); | ||
_inherits(CharacterState, _BaseState); | ||
_prototypeProperties(CharacterState, null, { | ||
_createClass(CharacterState, { | ||
test: { | ||
@@ -192,5 +186,3 @@ | ||
return character === charOrRegExp || charOrRegExp instanceof RegExp && charOrRegExp.test(character); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
@@ -209,14 +201,14 @@ }); | ||
var TokenState = (function (BaseState) { | ||
var TokenState = (function (_BaseState2) { | ||
function TokenState() { | ||
_classCallCheck(this, TokenState); | ||
if (BaseState != null) { | ||
BaseState.apply(this, arguments); | ||
if (_BaseState2 != null) { | ||
_BaseState2.apply(this, arguments); | ||
} | ||
} | ||
_inherits(TokenState, BaseState); | ||
_inherits(TokenState, _BaseState2); | ||
_prototypeProperties(TokenState, null, { | ||
_createClass(TokenState, { | ||
test: { | ||
@@ -234,5 +226,3 @@ | ||
return tokenClass.test(token); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
@@ -299,5 +289,2 @@ }); | ||
exports.TokenState = TokenState; | ||
exports.stateify = stateify; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.stateify = stateify; |
@@ -7,6 +7,9 @@ "use strict"; | ||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); }; | ||
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/****************************************************************************** | ||
@@ -37,3 +40,16 @@ Text Tokens | ||
_prototypeProperties(TextToken, { | ||
_createClass(TextToken, { | ||
toString: { | ||
/** | ||
String representing the type for this token | ||
@property type | ||
@default 'TOKEN' | ||
*/ | ||
value: function toString() { | ||
return this.v + ""; | ||
} | ||
} | ||
}, { | ||
test: { | ||
@@ -50,21 +66,4 @@ | ||
return value instanceof this; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
}, { | ||
toString: { | ||
/** | ||
String representing the type for this token | ||
@property type | ||
@default 'TOKEN' | ||
*/ | ||
value: function toString() { | ||
return this.v + ""; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
@@ -81,12 +80,12 @@ | ||
var DOMAIN = (function (TextToken) { | ||
var DOMAIN = (function (_TextToken) { | ||
function DOMAIN() { | ||
_classCallCheck(this, DOMAIN); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken != null) { | ||
_TextToken.apply(this, arguments); | ||
} | ||
} | ||
_inherits(DOMAIN, TextToken); | ||
_inherits(DOMAIN, _TextToken); | ||
@@ -101,3 +100,3 @@ return DOMAIN; | ||
var AT = (function (TextToken) { | ||
var AT = (function (_TextToken2) { | ||
function AT() { | ||
@@ -109,3 +108,3 @@ _classCallCheck(this, AT); | ||
_inherits(AT, TextToken); | ||
_inherits(AT, _TextToken2); | ||
@@ -122,3 +121,3 @@ return AT; | ||
var COLON = (function (TextToken) { | ||
var COLON = (function (_TextToken3) { | ||
function COLON() { | ||
@@ -130,3 +129,3 @@ _classCallCheck(this, COLON); | ||
_inherits(COLON, TextToken); | ||
_inherits(COLON, _TextToken3); | ||
@@ -141,3 +140,3 @@ return COLON; | ||
var DOT = (function (TextToken) { | ||
var DOT = (function (_TextToken4) { | ||
function DOT() { | ||
@@ -149,3 +148,3 @@ _classCallCheck(this, DOT); | ||
_inherits(DOT, TextToken); | ||
_inherits(DOT, _TextToken4); | ||
@@ -161,12 +160,12 @@ return DOT; | ||
var LOCALHOST = (function (TextToken) { | ||
var LOCALHOST = (function (_TextToken5) { | ||
function LOCALHOST() { | ||
_classCallCheck(this, LOCALHOST); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken5 != null) { | ||
_TextToken5.apply(this, arguments); | ||
} | ||
} | ||
_inherits(LOCALHOST, TextToken); | ||
_inherits(LOCALHOST, _TextToken5); | ||
@@ -182,3 +181,3 @@ return LOCALHOST; | ||
var TNL = (function (TextToken) { | ||
var TNL = (function (_TextToken6) { | ||
function TNL() { | ||
@@ -190,3 +189,3 @@ _classCallCheck(this, TNL); | ||
_inherits(TNL, TextToken); | ||
_inherits(TNL, _TextToken6); | ||
@@ -201,12 +200,12 @@ return TNL; | ||
var NUM = (function (TextToken) { | ||
var NUM = (function (_TextToken7) { | ||
function NUM() { | ||
_classCallCheck(this, NUM); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken7 != null) { | ||
_TextToken7.apply(this, arguments); | ||
} | ||
} | ||
_inherits(NUM, TextToken); | ||
_inherits(NUM, _TextToken7); | ||
@@ -221,3 +220,3 @@ return NUM; | ||
var PLUS = (function (TextToken) { | ||
var PLUS = (function (_TextToken8) { | ||
function PLUS() { | ||
@@ -229,3 +228,3 @@ _classCallCheck(this, PLUS); | ||
_inherits(PLUS, TextToken); | ||
_inherits(PLUS, _TextToken8); | ||
@@ -240,3 +239,3 @@ return PLUS; | ||
var POUND = (function (TextToken) { | ||
var POUND = (function (_TextToken9) { | ||
function POUND() { | ||
@@ -248,3 +247,3 @@ _classCallCheck(this, POUND); | ||
_inherits(POUND, TextToken); | ||
_inherits(POUND, _TextToken9); | ||
@@ -267,12 +266,12 @@ return POUND; | ||
var PROTOCOL = (function (TextToken) { | ||
var PROTOCOL = (function (_TextToken10) { | ||
function PROTOCOL() { | ||
_classCallCheck(this, PROTOCOL); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken10 != null) { | ||
_TextToken10.apply(this, arguments); | ||
} | ||
} | ||
_inherits(PROTOCOL, TextToken); | ||
_inherits(PROTOCOL, _TextToken10); | ||
@@ -287,3 +286,3 @@ return PROTOCOL; | ||
var QUERY = (function (TextToken) { | ||
var QUERY = (function (_TextToken11) { | ||
function QUERY() { | ||
@@ -295,3 +294,3 @@ _classCallCheck(this, QUERY); | ||
_inherits(QUERY, TextToken); | ||
_inherits(QUERY, _TextToken11); | ||
@@ -306,3 +305,3 @@ return QUERY; | ||
var SLASH = (function (TextToken) { | ||
var SLASH = (function (_TextToken12) { | ||
function SLASH() { | ||
@@ -314,3 +313,3 @@ _classCallCheck(this, SLASH); | ||
_inherits(SLASH, TextToken); | ||
_inherits(SLASH, _TextToken12); | ||
@@ -326,12 +325,12 @@ return SLASH; | ||
var SYM = (function (TextToken) { | ||
var SYM = (function (_TextToken13) { | ||
function SYM() { | ||
_classCallCheck(this, SYM); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken13 != null) { | ||
_TextToken13.apply(this, arguments); | ||
} | ||
} | ||
_inherits(SYM, TextToken); | ||
_inherits(SYM, _TextToken13); | ||
@@ -346,12 +345,12 @@ return SYM; | ||
var TLD = (function (TextToken) { | ||
var TLD = (function (_TextToken14) { | ||
function TLD() { | ||
_classCallCheck(this, TLD); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken14 != null) { | ||
_TextToken14.apply(this, arguments); | ||
} | ||
} | ||
_inherits(TLD, TextToken); | ||
_inherits(TLD, _TextToken14); | ||
@@ -368,12 +367,12 @@ return TLD; | ||
var WS = (function (TextToken) { | ||
var WS = (function (_TextToken15) { | ||
function WS() { | ||
_classCallCheck(this, WS); | ||
if (TextToken != null) { | ||
TextToken.apply(this, arguments); | ||
if (_TextToken15 != null) { | ||
_TextToken15.apply(this, arguments); | ||
} | ||
} | ||
_inherits(WS, TextToken); | ||
_inherits(WS, _TextToken15); | ||
@@ -452,19 +451,3 @@ return WS; | ||
_prototypeProperties(MultiToken, { | ||
test: { | ||
/** | ||
Is the given value an instance of this Token? | ||
@method test | ||
@static | ||
@param {Mixed} value | ||
*/ | ||
value: function test(token) { | ||
return token instanceof this; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, { | ||
_createClass(MultiToken, { | ||
toString: { | ||
@@ -484,5 +467,3 @@ | ||
return result.join(""); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -500,5 +481,3 @@ toHref: { | ||
return this.toString(); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -526,6 +505,18 @@ toObject: { | ||
}; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
}, { | ||
test: { | ||
/** | ||
Is the given value an instance of this Token? | ||
@method test | ||
@static | ||
@param {Mixed} value | ||
*/ | ||
value: function test(token) { | ||
return token instanceof this; | ||
} | ||
} | ||
}); | ||
@@ -542,3 +533,3 @@ | ||
var EMAIL = (function (MultiToken) { | ||
var EMAIL = (function (_MultiToken) { | ||
function EMAIL(value) { | ||
@@ -552,11 +543,9 @@ _classCallCheck(this, EMAIL); | ||
_inherits(EMAIL, MultiToken); | ||
_inherits(EMAIL, _MultiToken); | ||
_prototypeProperties(EMAIL, null, { | ||
_createClass(EMAIL, { | ||
toHref: { | ||
value: function toHref() { | ||
return "mailto:" + this.toString(); | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
@@ -574,3 +563,3 @@ }); | ||
var TEXT = (function (MultiToken) { | ||
var TEXT = (function (_MultiToken2) { | ||
function TEXT(value) { | ||
@@ -583,3 +572,3 @@ _classCallCheck(this, TEXT); | ||
_inherits(TEXT, MultiToken); | ||
_inherits(TEXT, _MultiToken2); | ||
@@ -595,3 +584,3 @@ return TEXT; | ||
var MNL = (function (MultiToken) { | ||
var MNL = (function (_MultiToken3) { | ||
function MNL(value) { | ||
@@ -604,3 +593,3 @@ _classCallCheck(this, MNL); | ||
_inherits(MNL, MultiToken); | ||
_inherits(MNL, _MultiToken3); | ||
@@ -616,3 +605,3 @@ return MNL; | ||
var URL = (function (MultiToken) { | ||
var URL = (function (_MultiToken4) { | ||
function URL(value) { | ||
@@ -626,5 +615,5 @@ _classCallCheck(this, URL); | ||
_inherits(URL, MultiToken); | ||
_inherits(URL, _MultiToken4); | ||
_prototypeProperties(URL, null, { | ||
_createClass(URL, { | ||
toHref: { | ||
@@ -683,5 +672,3 @@ | ||
return result; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
}, | ||
@@ -691,5 +678,3 @@ hasProtocol: { | ||
return this.v[0] instanceof PROTOCOL; | ||
}, | ||
writable: true, | ||
configurable: true | ||
} | ||
} | ||
@@ -710,5 +695,2 @@ }); | ||
exports.text = text; | ||
exports.multi = multi; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.multi = multi; |
@@ -22,3 +22,3 @@ "use strict"; | ||
var HASHTAG = (function (MultiToken) { | ||
var HASHTAG = (function (_MultiToken) { | ||
function HASHTAG(value) { | ||
@@ -32,3 +32,3 @@ _classCallCheck(this, HASHTAG); | ||
_inherits(HASHTAG, MultiToken); | ||
_inherits(HASHTAG, _MultiToken); | ||
@@ -35,0 +35,0 @@ return HASHTAG; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function noop(val) { | ||
@@ -17,2 +20,3 @@ return val; | ||
defaultProtocol: opts.defaultProtocol || "http", | ||
events: opts.events || null, | ||
format: opts.format || noop, | ||
@@ -37,5 +41,2 @@ formatHref: opts.formatHref || noop, | ||
exports.normalize = normalize; | ||
exports.resolve = resolve; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.resolve = resolve; |
{ | ||
"name": "linkifyjs", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"description": "Intelligent URL recognition, made easy", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "https://github.com/SoapBox/jQuery-linkify.git" | ||
"type": "git", | ||
"url": "https://github.com/SoapBox/jQuery-linkify.git" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"prepublish": "node_modules/.bin/gulp build", | ||
"test": "node_modules/.bin/gulp test" | ||
"prepublish": "rm -rf lib/* && node_modules/.bin/gulp build", | ||
"test": "node_modules/.bin/gulp coverage", | ||
"test-ci": "node_modules/.bin/gulp test-ci", | ||
"coverage": "./node_modules/coveralls/bin/coveralls.js < coverage/lcov.info" | ||
}, | ||
@@ -18,16 +20,16 @@ "author": "SoapBox Innovations (@SoapBoxHQ)", | ||
"devDependencies": { | ||
"amd-optimize": "0.4.x", | ||
"amd-optimize": "^0.4.3", | ||
"brfs": "^1.4.0", | ||
"chai": "^2.1.0", | ||
"closure-compiler": "0.2.x", | ||
"chai": "^2.1.1", | ||
"closure-compiler": "^0.2.6", | ||
"coveralls": "^2.11.2", | ||
"glob": "^4.4.1", | ||
"gulp": "3.8.x", | ||
"glob": "^5.0.3", | ||
"gulp": "^3.8.11", | ||
"gulp-babel": "^4.0.0", | ||
"gulp-closure-compiler": "0.2.x", | ||
"gulp-closure-compiler": "^0.2.14", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-istanbul": "^0.6.0", | ||
"gulp-jshint": "1.9.x", | ||
"gulp-mocha": "2.0.x", | ||
"gulp-rename": "1.2.x", | ||
"gulp-jshint": "^1.9.2", | ||
"gulp-mocha": "^2.1.0", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-replace": "^0.5.3", | ||
@@ -37,12 +39,13 @@ "gulp-uglify": "^1.1.0", | ||
"jsdom": "^3.0.0", | ||
"jshint-stylish": "1.0.x", | ||
"jshint-stylish": "^1.0.1", | ||
"karma": "^0.12.32", | ||
"karma-browserify": "^4.0.0", | ||
"karma-chrome-launcher": "0.1.x", | ||
"karma-mocha": "0.1.x", | ||
"karma-phantomjs-launcher": "0.1.x", | ||
"karma-sauce-launcher": "0.2.x", | ||
"lodash": "^3.3.1", | ||
"karma-chrome-launcher": "^0.1.7", | ||
"karma-firefox-launcher": "^0.1.6", | ||
"karma-mocha": "^0.1.10", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"karma-sauce-launcher": "^0.2.10", | ||
"lodash": "^3.9.3", | ||
"merge-stream": "^0.1.7", | ||
"mocha": "2.1.x" | ||
"mocha": "^2.2.1" | ||
}, | ||
@@ -49,0 +52,0 @@ "optionalDependencies": { |
211
README.md
# Linkify | ||
[![Node Dependencies](https://david-dm.org/SoapBox/jQuery-linkify/dev-status.png)](https://david-dm.org/SoapBox/jQuery-linkify#info=devDependencies&view=table) | ||
[![npm version](https://badge.fury.io/js/linkifyjs.svg)](https://www.npmjs.com/package/linkifyjs) | ||
[![Dependency Status](https://gemnasium.com/SoapBox/jQuery-linkify.svg)](https://gemnasium.com/SoapBox/jQuery-linkify) | ||
[![Build Status](https://travis-ci.org/SoapBox/jQuery-linkify.svg)](https://travis-ci.org/SoapBox/jQuery-linkify) | ||
[![Coverage Status](https://coveralls.io/repos/SoapBox/jQuery-linkify/badge.svg)](https://coveralls.io/r/SoapBox/jQuery-linkify) | ||
@@ -86,4 +89,4 @@ Linkify is a small yet comprehensive JavaScript plugin for finding URLs in plain-text and converting them to HTML links. It works with all valid URLs and email addresses. | ||
var linkify = require('linkifyjs'); | ||
require('linkifyjs/plugin/hashtag')(linkify); // optional | ||
var linkifyStr = require('linkifyjs/string'); | ||
require('linkifyjs/plugin/hashtag')(linkify); // optional | ||
``` | ||
@@ -123,3 +126,3 @@ | ||
// Linkify the #sidebar element | ||
linkifyElement(document.getElementById('#sidebar'), { | ||
linkifyElement(document.getElementById('sidebar'), { | ||
linkClass: 'my-link' | ||
@@ -156,2 +159,6 @@ }); | ||
**Plugins** _(optional)_ | ||
* **[hashtag](#linkify-plugin-hashtag)**<br> [`.min.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.min.js) · [`.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.js) · [`.amd.min.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.amd.min.js) · [`.amd.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.amd.js) | ||
**Interfaces** _(recommended - include at least one)_ | ||
@@ -164,6 +171,2 @@ | ||
**Plugins** _(optional)_ | ||
* **[hashtag](#linkify-plugin-hashtag)**<br> [`.min.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.min.js) · [`.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.js) · [`.amd.min.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.amd.min.js) · [`.amd.js`](https://github.com/nfrasser/linkify-shim/raw/master/linkify-plugin-hashtag.amd.js) | ||
## API | ||
@@ -181,3 +184,3 @@ | ||
### Standard linkify | ||
### Standard `linkify` | ||
@@ -210,3 +213,3 @@ #### Installation | ||
##### linkify.find _(str)_ | ||
##### `linkify.find` _(`str` [, `type`])_ | ||
@@ -218,5 +221,13 @@ Finds all links in the given string | ||
* _`String`_ **`str`** Search string | ||
* _`String`_ [**`type`**] (Optional) only find links of the given type | ||
**Returns** _`Array`_ List of links where each element is a hash with properties `type`, `value`, and `href` | ||
**Returns** _`Array`_ List of links where each element is a hash with properties `type`, `value`, and `href`. | ||
* `type` is the type of entity found. Possible values are | ||
- `'url'` | ||
- `'email'` | ||
- `'hashtag'` (with Hashtag plugin) | ||
* `value` is the original entity substring. | ||
* `href` should be the value of this link's `href` attribute. | ||
```js | ||
@@ -229,14 +240,17 @@ linkify.find('For help with GitHub.com, please email support@github.com'); | ||
```js | ||
[{ | ||
[ | ||
{ | ||
type: 'url', | ||
value: 'GitHub.com', | ||
href: 'http://github.com', | ||
}, { | ||
}, | ||
{ | ||
type: 'email', | ||
value: 'support@github.com', | ||
href: 'mailto:support@github.com' | ||
}] | ||
} | ||
] | ||
``` | ||
##### linkify.test _(str)_ | ||
##### `linkify.test` _(`str` [, `type`])_ | ||
@@ -247,3 +261,4 @@ Is the given string a link? Not to be used for strict validation - See [Caveats](#) | ||
* `String` **`str`** Test string | ||
* _`String`_ **`str`** Test string | ||
* _`String`_ [**`type`**] (Optional) returns `true` only if the link is of the given type (see `linkify.find`), | ||
@@ -257,3 +272,3 @@ **Returns** _`Boolean`_ | ||
#### linkify.tokenize _(str)_ | ||
#### `linkify.tokenize` _(`str`)_ | ||
@@ -264,3 +279,3 @@ Internal method used to perform lexicographical analysis on the given string and output the resulting token array. | ||
* `String` **`str`** | ||
* _`String`_ **`str`** | ||
@@ -270,3 +285,3 @@ **Returns** _`Array`_ | ||
### linkify-jquery | ||
### `linkify-jquery` | ||
@@ -278,7 +293,10 @@ Provides the Linkify jQuery plugin. | ||
##### Node.js/io.js/Browserify | ||
```js | ||
var $ = require('jquery'); | ||
require('linkifyjs/jquery')($); | ||
require('linkifyjs/jquery')($, document); | ||
``` | ||
Where the second argument is your `window.document` implementation (not required for Browserify). | ||
##### AMD | ||
@@ -317,3 +335,3 @@ | ||
* `Object` [**`options`**] [Options hash](#options) | ||
* _`Object`_ [**`options`**] [Options hash](#options) | ||
@@ -336,3 +354,3 @@ See [all available options](#options). | ||
### linkify-string | ||
### `linkify-string` | ||
@@ -368,3 +386,3 @@ Interface for replacing links within native strings with anchor tags. Note that this function will ***not*** parse HTML strings properly - use [`linkify-element`](#linkify-element) or [`linkify-jquery`](#linkify-jquery) instead. | ||
**Usage** | ||
#### Usage | ||
@@ -387,4 +405,4 @@ ```js | ||
* `String` **`str`** String to linkify | ||
* `Object` [**`options`**] [Options hash](#) | ||
* _`String`_ **`str`** String to linkify | ||
* _`Object`_ [**`options`**] [Options hash](#) | ||
@@ -398,45 +416,60 @@ **Returns** _`String`_ Linkified string | ||
#### hashtag | ||
**Note:** Plugins should be included before interfaces. | ||
Adds basic support for Twitter-style hashtags. | ||
#### General Installation | ||
##### Node.js/io.js/Browserify | ||
```js | ||
// Node.js/Browserify | ||
var linkify = require('linkifyjs'); | ||
require('linkifyjs/plugins/hashtag')(linkify); | ||
var linkify = require('linkifyjs') | ||
require('linkifyjs/plugin/<name>')(linkify); | ||
``` | ||
##### AMD | ||
```html | ||
<!-- Global `linkifyStr` --> | ||
<script src="linkify.js"></script> | ||
<script src="linkify-plugin-hashtag.js"></script> | ||
<!-- AMD --> | ||
<script src="linkify.amd.js"></script> | ||
<script src="linkify-plugin-hashtag.amd.js"></script> | ||
<script> | ||
require(['linkify'], function (linkify) { | ||
// ... | ||
}); | ||
</script> | ||
<script src="linkify-plugin-<name>.amd.js"></script> | ||
``` | ||
**Usage** | ||
##### Browser globals | ||
```html | ||
<script src="linkify.js"></script> | ||
<script src="linkify-plugin-<name>.js"></script> | ||
``` | ||
#### `hashtag` Plugin | ||
Adds basic support for Twitter-style hashtags. | ||
```js | ||
var linkify = require('linkifyjs'); | ||
require('linkifyjs/plugins/hashtag')(linkify); | ||
``` | ||
```js | ||
var options = {/* ... */}; | ||
var str = "Linkify is #super #rad"; | ||
var str = "Linkify is #super #rad2015"; | ||
linkify.find(str); | ||
/* [ | ||
{type: 'hashtag', value: "#super", href: "#super"}, | ||
{type: 'hashtag', value: "#rad", href: "#rad"} | ||
] */ | ||
``` | ||
// If the linkifyStr interface has also been included | ||
linkifyStr(str) | ||
Returns the following array | ||
```js | ||
[ | ||
{ | ||
type: 'hashtag', | ||
value: "#super", | ||
href: "#super" | ||
}, | ||
{ | ||
type: 'hashtag', | ||
value: "#rad2015", | ||
href: "#rad2015" | ||
} | ||
] | ||
``` | ||
## Options | ||
@@ -448,33 +481,62 @@ | ||
var options = { | ||
tagName: 'span', | ||
defaultProtocol: 'https', | ||
target: '_parent', | ||
nl2br: true, | ||
linkClass: 'a-new-link', | ||
linkAttributes: { | ||
rel: 'nofollow' | ||
}, | ||
format: function (link, type) { | ||
if (type === 'hashtag') { | ||
link = link.toLowerCase(); | ||
} | ||
return link; | ||
}, | ||
formatHref: function (link, type) { | ||
if (type === 'hashtag') { | ||
link = 'https://twitter.com/hashtag/' + link.replace('#', ''); | ||
} | ||
return link; | ||
defaultProtocol: 'http', | ||
format: null, | ||
formatHref: null, | ||
linkAttributes: null, | ||
linkClass: 'linkified', | ||
nl2br: false, | ||
tagName: 'a', | ||
target: function (type) { | ||
return type === 'url' ? '_blank' : null; | ||
} | ||
}; | ||
``` | ||
// jQuery | ||
$('selector').linkify(options); | ||
### Usage | ||
// String | ||
linkifyStr(str, options); | ||
str.linkify(options); | ||
```js | ||
linkifyStr(str, options); // or `str.linkify(options)` | ||
linkifyElement(document.getElementById(id), options); | ||
$(selector).linkify(options); | ||
``` | ||
#### `defaultProtocol` | ||
**Type**: `String`<br> | ||
**Default**: `'http'`<br> | ||
**Values**: `'http'`, `'https'`, `'ftp'`, `'ftps'`, etc.<br> | ||
**Data API**: `data-linkify-default-protocol`<br> | ||
Protocol that should be used in `href` attributes for URLs without a protocol (e.g., `github.com`). | ||
#### `format` | ||
**Type**: `Function (String value, String type)`<br> | ||
**Default**: `null`<br> | ||
Format the text displayed by a linkified entity. e.g., truncate a long URL. | ||
```js | ||
'http://github.com/SoapBox/linkifyjs/search/?q=this+is+a+really+long+query+string'.linkify({ | ||
format: function (value, type) { | ||
if (type === 'url' && value.length > 50) { | ||
value = value.slice(0, 50) + '…'; | ||
} | ||
return value; | ||
} | ||
}); | ||
``` | ||
#### `formatHref` | ||
#### `nl2br` | ||
#### `tagName` | ||
#### `target` | ||
#### `linkAttributes` | ||
#### `linkClass` | ||
## Plugin API | ||
@@ -486,8 +548,5 @@ | ||
* | ||
## Contributing | ||
## Authors | ||
Linkify is handcrafted with Love by [SoapBox Innovations, Inc](http://soapboxhq.com). |
Sorry, the diff of this file is not supported yet
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2692507
189
13181
533
29
5
2
10
1