linkifyjs

repository·main·Indexed 24 days ago

https://github.com/nfrasser/linkifyjs

A lightweight JavaScript library for intelligent link recognition. It finds URLs, emails, and other patterns in plain text or HTML and converts them into HTML <a> tags or extracts metadata. The ecosystem includes environment-specific packages for React, jQuery, DOM elements, and HTML strings, as well as plugins for detecting hashtags, @mentions, ticket identifiers, IP addresses, and custom keywords.

Tokens
6.7K
Snippets
28
Records
61
Agent score
82%

What's inside linkifyjs

  1. Available linkifyjs ecosystem packages

    main

    The core linkifyjs library can be extended or used in specific environments via specialized packages. Depending on your use case, you may want to install one of the following instead of or in addition to the core library:

    • Environment specific:

      • linkify-html: For processing HTML strings.
      • linkify-react: As a React component.
      • linkify-jquery: As a jQuery plugin.
      • linkify-element: For working directly with DOM Elements.
      • linkify-string: For plain-text processing.
    • Plugins for detection:

      • linkify-plugin-hashtag: For detecting #hashtags.
      • linkify-plugin-mention: For detecting @mentions.
      • linkify-plugin-ticket: For detecting ticket identifiers.
      • linkify-plugin-ip: For detecting IP addresses.
      • linkify-plugin-keyword: For detecting specific keywords.
  2. Extend Linkify with plugins

    main
    By default, Linkify only detects web URLs and email addresses. To detect other patterns like #hashtags, @mentions, or ticket numbers, you must install and use separate plugin packages (e.g., linkify-plugin-hashtag, linkify-plugin-mention).
  3. Import linkify-plugin-mention

    main

    The mention plugin works by extending the core linkifyjs functionality. You must import the plugin after importing linkifyjs to ensure the plugin registers itself correctly.

    // Using CommonJS (require)
    const linkify = require('linkifyjs');
    require('linkify-plugin-mention');
    
    // Using ES modules (import)
    import * as linkify from 'linkifyjs';
    import 'linkify-plugin-mention';
  4. Initialize linkify-jquery in environments without a global document

    main

    If your environment does not have a window.document global available, you must manually provide the jQuery instance and the document object to the plugin during initialization.

    // Using CommonJS (require)
    const $ = require('jquery');
    require('linkify-jquery')($, document);
    
    // Using ES modules (import)
    import $ from 'jquery';
    import linkifyJq from 'linkify-jquery';
    linkifyJq($, document);