Package Exports
- linkifyjs
- linkifyjs/element
- linkifyjs/html
- linkifyjs/lib/linkify
- linkifyjs/plugins/hashtag
- linkifyjs/string
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (linkifyjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Linkify
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.
A build repository is maintained here.
Jump to
Features
- Accuracy
Linkify uses a (close to) complete list of valid top-level domains to ensure that only valid URLs and email addresses are matched. - Speed
Each string is analyzied exactly once to detect every kind of linkable entity - Extensibility
Linkify is designed to be fast and lightweight, but comes with a powerful plugin API that lets you detect even more information like #hashtags and @mentions. - Small footprint
Linkify and its jQuery interface clock in at approximately 15KB minified (5KB gzipped) - approximately 50% the size of Twitter Text - Modern implementation
Linkify is written in ECMAScript6 and compiles to ES5 for modern JavaScript runtimes.- Linkify is compatible with all modern browsers, as well as Internet Explorer 9 and up. Full IE8 support coming soon.
Demo
Installation and Usage
Download the latest release, or install via NPM
npm install linkifyjs
or Bower
bower install linkifyjs
Quick Start
Add linkify and linkify-jquery to your HTML following jQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="linkify.min.js"></script>
<script src="linkify-jquery.min.js"></script>
Find all links and convert them to anchor tags
$('p').linkify();
$('#sidebar').linkify({
target: "_blank"
});
Find all links in the given string
linkify.find('Any links to github.com here? If not, contact test@example.com');
Returns the following array
[
{
type: 'url',
value: 'github.com',
href: 'http://github.com'
},
{
type: 'email',
value: 'test@example.com',
href: 'mailto:test@example.com'
}
]
Node.js/io.js/Browserify
var linkify = require('linkifyjs');
require('linkifyjs/plugins/hashtag')(linkify); // optional
var linkifyHtml = require('linkifyjs/html');
Example string usage
linkifyHtml('The site github.com is #awesome.', {
defaultProtocol: 'https'
});
Returns the following string
'The site <a href="https://github.com">github.com</a> is <a href="#awesome">#awesome</a>.'
AMD
<script src="r.js"></script>
<script src="linkify.amd.js"></script>
<script src="linkify-plugin-hashtag.amd.js"></script> <!-- optional -->
<script src="linkify-element.amd.js"></script>
require(['linkify'], function (linkify) {
linkify.test('github.com'); // true
linkify.test('github.com', 'email'); // false
});
require(['linkify-element'], function (linkifyElement) {
// Linkify the #sidebar element
linkifyElement(document.getElementById('sidebar'), {
linkClass: 'my-link'
});
// Linkify all paragraph tags
document.getElementsByTagName('p').map(linkifyElement);
});
Note that if you are using linkify-jquery.amd.js
, a jquery
module must be defined.
Browser globals
<script src="jquery.js"></script>
<script src="linkify.js"></script>
<script src="linkify-string.js"></script>
<script src="linkify-jquery.js"></script>
linkify.test('dev@example.com'); // true
var htmlStr = linkifyStr('Check out soapboxhq.com it is great!');
$('p').linkify();
Downloads
Download the latest release or clone the build repository.
linkify (required)
.min.js
· .js
· .amd.min.js
· .amd.js
Plugins (optional)
- hashtag
.min.js
·.js
·.amd.min.js
·.amd.js
Interfaces (recommended - include at least one)
- jquery
.min.js
·.js
·.amd.min.js
·.amd.js
- html
.min.js
·.js
·.amd.min.js
·.amd.js
- element (Included with linkify-jquery)
.min.js
·.js
·.amd.min.js
·.amd.js
- string
.min.js
·.js
·.amd.min.js
·.amd.js
API Documentation
View full documentation at soapbox.github.io/linkifyjs/docs/.
Caveats
The core linkify library (excluding plugins) attempts to find emails and URLs that match RFC specifications. However, it doesn't always get it right.
Here are a few of the known issues.
- Non-standard email local parts delimited by " (quote characters)
- Emails with quotes in the localpart are detected correctly, unless the quotes contain certain characters like
@
.
- Emails with quotes in the localpart are detected correctly, unless the quotes contain certain characters like
- Slash characters in email addresses
- Non-latin domains or TLDs are not supported (support may be added via plugin in the future)
Contributing
Check out CONTRIBUTING.md.
License
MIT
Authors
Linkify is built with Love™ and maintained by SoapBox Innovations.