Linkify is a JavaScript plugin for finding links in plain-text and converting them to HTML tags.
  • JavaScript 96.2%
  • HTML 3.5%
  • Shell 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2016-09-27 18:57:55 -04:00
assets Fixing download links on demo page 2013-12-15 18:00:35 -05:00
plugins Tickets plugin (#156) 2016-08-16 22:48:11 -04:00
src Single quotes should be treated as punctuation (#165) 2016-09-27 18:52:56 -04:00
tasks Bugfix in quick-es3 task 2016-08-17 23:19:24 -04:00
templates Linkify global along with LinkifyReact 2016-09-01 21:54:30 -04:00
test Single quotes should be treated as punctuation (#165) 2016-09-27 18:52:56 -04:00
.babelrc Build upgrades (#131) 2016-04-25 18:42:56 -04:00
.editorconfig Boilerplate'd , added node/bower/grunt for development 2013-12-13 22:39:26 -05:00
.eslintrc Development upgrades (#153) 2016-08-13 19:04:08 -04:00
.gitignore Adding build symlink so QUnit tests run properly 2015-12-23 18:43:08 -05:00
.npmignore Development upgrades (#153) 2016-08-13 19:04:08 -04:00
.travis.yml Development upgrades (#153) 2016-08-13 19:04:08 -04:00
CHANGELOG.md v2.1.2 2016-09-27 18:57:55 -04:00
CONTRIBUTING.md Development upgrades (#153) 2016-08-13 19:04:08 -04:00
element.js Build upgrades (#131) 2016-04-25 18:42:56 -04:00
gulpfile.js Remove build-legacy task 2016-09-01 21:55:14 -04:00
html.js Build upgrades (#131) 2016-04-25 18:42:56 -04:00
index.js Switching to ES6 Module system 2015-01-12 18:30:37 -05:00
jquery.js Build upgrades (#131) 2016-04-25 18:42:56 -04:00
LICENSE Update LICENSE 2016-04-29 16:47:24 -04:00
package.json v2.1.2 2016-09-27 18:57:55 -04:00
polyfill.js IE8 Support (#137) 2016-05-15 22:50:49 -04:00
react.js v2.1.0 2016-09-01 22:12:26 -04:00
README.md Changelog v2.1 2016-09-01 21:55:51 -04:00
run-tests.sh Updating test and dev dependencies 2016-07-01 16:10:44 -04:00
string.js Build upgrades (#131) 2016-04-25 18:42:56 -04:00
tlds.js Optimize class code to reduce file size (#147) 2016-07-01 23:00:44 -04:00

Linkify

npm version Dependency Status Build Status Build Status Coverage Status

Build Status

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 analyzed 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 8 and up.

Demo

Launch demo

Installation and Usage

View full documentation.

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.12.4/jquery.min.js"></script>
<script src="linkify.min.js"></script>
<script src="linkify-jquery.min.js"></script>

Note: A polyfill is required for Internet Explorer 8.

$('p').linkify();
$('#sidebar').linkify({
    target: "_blank"
});
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'
  }
]

See all available options

Node.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'), {
    className: '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="react.js"></script>
<script src="react-dom.js"></script>
<script src="linkify.js"></script>
<script src="linkify-react.js"></script>
linkify.test('dev@example.com'); // true

ReactDOM.render(
  <Linkify options={{ignoreTags: ['style']}}>
    Check out soapboxhq.com it is great!
  </Linkify>,
  document.getElementById('#container');
);

Internet Explorer

Linkify natively supports Internet Explorer 9 and above. Internet Explorer 8 is supported with a polyfill.

You can use either es5-shim (sham also required) or the provided linkify-polyfill.js:

<script src="jquery.js"></script>

<!--[if IE 8]>
<script src="linkify-polyfill.js"></script>
<![endif]-->
<script src="linkify.js"></script>
<script src="linkify-jquery.js"></script>

Downloads

Download the latest release or clone the build repository.

linkify (required)
.min.js · .js · .amd.min.js · .amd.js

Plugins (optional)

Interfaces (recommended - include at least one)

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 @.
  • 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.