A JavaScript library for linkification stuff. Used by linkify-plus-plus.
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/27630/178765/linkify-plus-plus-core.js
A JavaScript library for linkification stuff. Used by linkify-plus-plus.
https://rawgit.com/eight04/linkify-plus-plus-core/master/demo/demo.html
This module exports 2 classes.
npm install -S linkify-plus-plus-core
There is also a browserified version in dist folder. Just add
<script src="path/to/linkify-plus-plus-core.js"></script>
and require() it as
var {UrlMatcher, Linkifier} = require("linkify-plus-plus-core");
// create a matcher
var matcher = new UrlMatcher();
for (var link of matcher.match(text)) {
// matcher.match() returns a generator, yielding an object for each match result
console.log(link.start, link.end, link.text, link.url);
}
// Linkifier needs a matcher to work
var linkifier = new Linkifier({matcher: matcher});
// Linkifier will walk through the DOM tree, match url against all text nodes, and replace them with anchor element.
linkifier.linkify(document.body).then(elapse => {
console.log(`finished in ${elapse}ms`);
}, err => {
console.log("failed with error:", err);
});
This module exports
<a> element.The options object, all properties are optional:
["file:///\\S+", "magnet:\\?\\S+"]standalone option. Allow some characters to be placed between whitespace and link. Some common characters are {[("'.standalone option. Allow some characters to be placed between whitespace and link. Some common characters are '")]},.;?!.The generator yielding matched result. The result object:
.url doesn't always equal .text, that .text might lack of the protocol but .url is always a full URL.There are also some properties for each parts of the URL: .protocol, .auth, .domain, .port, .path.
The options object:
A matcher is an object, having a .match method, which accepts a string and returns an iterable of matched result.
The match result must have .start, .end, .text, and .url properties described above.
A function recieving an element and returning a boolean to decide if the element should be linkified. Note that the elements in INVALID_TAGS are already filtered out before the validator.
target="_blank" to the link.<img> for the link if the url looks like an image.Linkify an element. The linkifier would walk through the DOM tree, collect text node and <wbr> tags, match link with matcher, and convert them into links.
When finished, the promise is resolved with elapsed time. When timeout, the promise is rejected with an error.
In the very old days, the script is based on Linkify Plus. Although it has been rewritten multiple times, the original license can be found at LICENSE.
TLD list is grabbed from http://data.iana.org/TLD/tlds-alpha-by-domain.txt.
TLD count is grabbed from http://research.domaintools.com/statistics/tld-counts/.
Version 0.1.0 (Feb 23, 2017):