Linkifyjs
JavaScript plugin for finding links in plain-text and converting them to HTML <a> tags.
Stars
Size
Forks
Open Issues
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.
Jump to
- Features
- Demo
- Installation and Usage
- Browser Support
- Node.js Support
- Downloads
- API Documentation
- Contributing
- License
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:
npm install linkifyjs linkify-html
Quick Start
When developing in an environment with JavaScript module loader such as Webpack,
use an import statement:
import * as linkify from 'linkifyjs';
import linkifyHtml from 'linkify-html';
Or in Node.js with CommonJS modules
const linkify = require('linkifyjs');
const linkifyHtml = require('linkify-html');
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.
Usage
Example 1: Convert all links to <a> tags in the given string
const options = { defaultProtocol: 'https' };
linkifyHtml('Any links to github.com here? If not, contact test@example.com', options);
Returns the following string:
'Any links to <a href="https://github.com">github.com</a> here? If not, contact <a href="mailto:test@example.com">test@example.com</a>';
To modify the resulting links with a target attribute, class name and more, use
the available options.
Example 2: 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',
isLink: true,
href: 'http://github.com',
start: 13,
end: 23,
},
{
type: 'email',
value: 'test@example.com',
isLink: true,
href: 'mailto:test@example.com',
start: 46,
end: 62,
},
];
Example 3: Check whether a string is a valid link:
Check if as string is a valid URL or email address:
linkify.test('github.com'); // true
Check if a string is a valid email address:
linkify.test('github.com', 'email'); // false
linkify.test('noreply@github.com', 'email'); // true
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.
Browser Support
Linkify natively supports all modern browsers.
Node.js Support
Linkify is tested on Node.js 14 and up. Older Node.js versions are unofficially
supported.
Downloads
Download the latest release
API Documentation
View full documentation at linkify.js.org/docs
Contributing
Check out CONTRIBUTING.md.
License
MIT
Authors
Linkify is made with β€οΈ by @nfrasser
- Add support for full width middle dot
γ»in hashtag plugin - Development updates for newest Node.js versions
- Fix HTML entity
&symbol double-encoding in linkify-html - Support for full-width brackets, full-width less-than/greater-than signs and corner bracket as delimiters
- Ensure linkify.find respects validate option
- Slightly simpler TLDs encoding/parsing
- Fix jsdoc in linkify-react
- Improved parsing of URLs with symbols
- Ensure function options get called with unformatted href
- Drop support for Safari 10
- Reduce core bundle file size by ~30%
- Restore support for email address with scheme local part
- Allow hashtags with emojis
- Fix email address detection with domains containing numbers
- Restore nl2br option for linkify-html
- Fixed duplicate key warning in linkify-react with multiple children
- Removed deprecated
linkifyjs/string,linkifyjs/html,linkifyjs/plugins/*
packages. Uselinkify-string,linkify-htmlandlinkify-plugin-*instead. - Refactored scanner internals break custom link plugins created with Linkify v3
- Links that begin with
mailto:now have typeurlinstead ofemail - Drop official IE 11 support
linkify-plugin-ipplugin for detecting IPv4 and IPv6 addresseslinkify-plugin-keywordplugin for detecting arbitrary keywordslinkify.find()function accepts anoptionsargument for output formatting- New
renderoption to override link rendering - Second
optionalSlashSlashargument forregisterCustomProtocolto allow links that don't require//afterscheme: - Link token methods
toFormattedString(options),toFormattedHref(options)andtoFormattedObject(options)that accept alinkify.Optionsobject - More granular scanner tokens for improved plugin flexibility
linkify-react: Newasproperty (alias fortagName)- Improved link detection with mixed languages
- Consistent option availability across interfaces (including
truncate) linkify-html: Improved HTML entity parsing- Fix potential Cross-Site Scripting issue when using
linkify-html - Expose ES6 modules with
"module"field inpackage.json - Add linkifyjs ES6 module build
- Correctly detect hashtags with underscores
- Fix plugin import bug
- Fix
linkify-stringandlinkify-htmltype declarations - Fix React component type declarations
- Include LICENSE file in all published packages
- React, jQuery and Element interfaces moved to dedicated packages at
linkify-react,linkify-jqueryandlinkify-elementrespectively: - Remove default
class="linkified"from all discovered links. Opt back in by setting theclassNameoption:linkifyStr(str, { className: 'linkified' }); - Remove default
target="_blank"attribute for discovered URLs. Opt back in by setting thetargetoption:linkifyHtml(str, { target: (href, type) => type === 'url' && '_blank', }); - React component: Remove outer
<span>tag wrapper in favour of tag-lessReact.Fragmentfor React >=16. To opt back-in, settagName='span':<Linkify tagName="span">{content}</Linkify> - AMD module interface is no longer provided. Use an ESM bundler instead.
- Plugins imported after linkify is called on a string for the first time will not longer work. Import all plugins before calling a linkify core or interface function.
- Custom plugin API is not compatible with previous API in Linkify v2
- Dropped support for Internet Explorer versions 9 and 10. IE11 is still supported
- Dropped support for React versions <15
- Use dedicated packages
linkify-stringandlinkify-htmlinstead oflinkifyjs/stringandlinkifyjs/html. The embedded packages will be removed in v4.0 - Use dedicated plugin packages
linkify-plugin-[PLUGIN]instead oflinkifyjs/plugin/[PLUGIN]. The embedded packages will be removed in v4.0 - Full Internationalized Domain (IDN) and Emoji domain support πΊπ³πβοΈππ! Detect URLs, #hashtags and @mentions in any language
- ~10x faster startup; ~4x faster combined startup + first run
- Custom protocols with
linkify.registerCustomProtocol('protocol') - Modernized codebase and build system
- Add new
reloption at top level as an alternate way of including it inattributes - New and improved plugin API
- TypeScript definitions included in published packages
linkify.find()output includes start and end indexes for where in the string a link was found-
Plugins no longer need to be called on linkify after import
// Before import * as linkify from 'linkifyjs'; import hashtag from 'linkifyjs/plugins/hashtag'; hashtag(linkify); // After import * as linkify from 'linkifyjs'; import 'linkifyjs/plugins/hashtag'; - Move optional dependencies to peerdependencies (#282)
- Fix
npm installdisplays vulnerabilities. (#265) - Fix typo (#275)
- Allow mentions with inner @ sign for federated mentions - thanks @juliushaertl!
- Drop official support for Internet Explorer 8 and Node.js 6 (still supported unofficially but may break in future releases)
- Update dev dependencies
- Update dependencies (#243)
- Ignore .babelrc file (854e6fc)
- Fix a bug where unique element IDs aren't unique (#215)
- Update tlds.js (#213)
- Automated browser test fixes (#224)
- Add partialProtocolMailtoStates to domainStates (#210)
- Use Object.defineProperty to extend String prototype so that 'linkify' function is not enumerable (#197)
- Allow null overrides in options for target and className (#189)
- React plugin compatibility updates
- Add explicit support for mailto: addresses (#186)
- Add support for mentions containing dots (#185)
- URL followed by
now works as expected in linkify-html (#184) - Small dependency updates (#183)
- Drop deprecated babel-preset-es2015-loose dependency (#172)
- Web workers support (#168)
- Links in angle brackets (#166)
- Single quotes should be treated as punctuation (#165)
- Detect additional whitespace characters (#163)
- The
dist/jquery.linkify.js1.x legacy browser files have been permanently
removed from the release bundle.- Use
linkify.jsandlinkify-jquery.jsinstead.
- Use
- The deprecated
newLineoption from linkify 1.x has been completely removed.- Use the
nl2broption instead.
- Use the
- New React.js interface
- @mention plugin
- GitHub-style ticket/issue reference plugin
- Improved option definitions
- Options that take functions with value and type arguments can now be
specified as objects, where each key is the target link type.
- Options that take functions with value and type arguments can now be
- The
linkAttributesoption is deprecated in favour of justattributes. - The
linkClassoption is deprecated in favour ofclassName. - The default
.linkifiedclass is deprecated and will be fully removed
in a future release. - Build optimizations to make compiled AMD payload smaller
- Bugfix in quick-es3 task
- Make better use of ES6 modules and rollup
- Tickets plugin (#156)
- Additional Mentions features, enhancements, and tests (#155)
- Mentions plugin (#111)
- Revamped options utility (#154)
- Linkify React Interface (#150)
- Development upgrades (#153)
- Correct trailing symbol parsing (#149)
- Linkify element fixes (#148)
- Optimize class code to reduce file size (#147).
- Update test and dev dependencies
- Allow uglify to mangle properties, except for the specified ones (#146)
- Updated tlds.js (#121)
- Fixing element interface invalid DOM node error (#141)
- Updated build system and development dependencies
- IE8 Support
- Internal API updates
- New link-detection technique based on lexicographical analysis via two-stage scanner - essentially regexp with more flexibility.
- Faster, less destructive DOM manipulation.
- Node.js API via
var linkify = require('linkifyjs'); - Internal plugin system so you can require only features you need. e.g.,
require('linkifyjs/plugins/hashtag')(linkify); - Browser modules (Browserify, AMD)
- Mocha Unit tests
- ES6 Implementation
- Updated documentation
- Repository name change
Linkify Changelog
v4.1.4
v4.1.3
v4.1.2
v4.1.1
v4.1.0
v4.0.2
v4.0.1
v4.0.0
BREAKING CHANGES
Added
Fixed
v3.0.5
v3.0.4
v3.0.3
v3.0.2
v3.0.1
v3.0.0
BREAKING CHANGES
Deprecations
All Changes
v2.1.9
v2.1.8
v2.1.7
v2.1.6
v2.1.5
v2.1.4
v2.1.3
v2.1.2
v2.1.1
v2.1.0
BREAKING CHANGES
Features
Deprecations
To maintain compatibility with versions >= 2.1, make sure options objects
include these properties instead of linkAttributes and linkClass