Linkify

JavaScript plugin for finding links in plain-text and converting them to HT...

README

Linkify


Linkify is a JavaScript plugin. Use Linkify to find links in plain-text and
convert them to HTML <a> tags. It automatically highlights URLs,
#hashtags, @mentions and more.

Features


Detect URLs and email addresses
#hashtag, @mention and #-ticket plugins
React and jQuery support
Multi-language and emoji support
Custom link plugins
Fast, accurate and small footprint (20kB minified, 11kB gzipped)
99% test coverage
Compatible with all modern browsers (Internet Explorer 11 and up)

Demo


Installation and Usage



Download the latest release for direct use in the browser, or install via NPM:

  1. ```
  2. npm install linkifyjs linkify-html
  3. ```

Quick Start


When developing in an environment with JavaScript module loader such as Webpack,
use an import statement:

  1. ```js
  2. import * as linkify from 'linkifyjs';
  3. import linkifyHtml from 'linkify-html';
  4. ```

Or in Node.js with CommonJS modules

  1. ```js
  2. const linkify = require('linkifyjs');
  3. const linkifyHtml = require('linkify-html');
  4. ```

Note: When linkify-ing text that does not contain HTML, install and use the
linkify-string package instead of linkify-html. [Read more about Linkify's
interfaces](https://linkify.js.org/docs/interfaces.html).

Usage


Example 1: Convert all links to <a> tags in the given string


  1. ```js
  2. const options = { defaultProtocol: 'https' };
  3. linkifyHtml('Any links to github.com here? If not, contact test@example.com', options);
  4. ```

Returns the following string:

  1. ```js
  2. 'Any links to github.com here? If not, contact test@example.com'
  3. ```

To modify the resulting links with a target attribute, class name and more, [use
the available options](https://linkify.js.org/docs/options.html).

Example 2: Find all links in the given string


  1. ```js
  2. linkify.find('Any links to github.com here? If not, contact test@example.com');
  3. ```

Returns the following array

  1. ```js
  2. [
  3.   {
  4.     type: 'url',
  5.     value: 'github.com',
  6.     isLink: true,
  7.     href: 'http://github.com',
  8.     start: 13,
  9.     end: 23
  10.   },
  11.   {
  12.     type: 'email',
  13.     value: 'test@example.com',
  14.     isLink: true,
  15.     href: 'mailto:test@example.com',
  16.     start: 46,
  17.     end: 62
  18.   }
  19. ]
  20. ```

Example 3: Check whether a string is a valid link:


Check if as string is a valid URL or email address:

  1. ```js
  2. linkify.test('github.com'); // true
  3. ```

Check if a string is a valid email address:

  1. ```js
  2. linkify.test('github.com', 'email'); // false
  3. linkify.test('noreply@github.com', 'email'); // true
  4. ```

Usage with React, jQuery or the browser DOM


Read the interface documentation  to learn how to use linkify when working with a specific JavaScript environment such as React.

Plugins for @mentions, #hashtags and more


By default Linkify will only detect and highlight web URLs and e-mail addresses.
Plugins for @mentions, #hashtags and more may be installed separately. [Read the
plugin documentation](https://linkify.js.org/docs/plugins.html).

Browser Support


Linkify natively supports all modern browsers.

Node.js Support


Linkify is tested on Node.js 10 and up. Older Node.js versions are unofficially
supported.

Downloads


Download the [latest release](https://github.com/Hypercontext/linkifyjs/releases)

API Documentation


View full documentation at linkify.js.org/docs

Contributing


Check out CONTRIBUTING.md.

License


MIT

Authors


Linkify is made with ❤️ by Hypercontext and @nfrasser