Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Gem Version Build Status

This gem is a port of the linkify-it javascript package by Vitaly Puzrin, that is used for the markdown-it package.

Currently synced with linkify-it 2.0.3

Links recognition library with full unicode support. Focused on high quality link pattern detection in plain text. For use with both Ruby and RubyMotion.

Javascript Demo


  • Full unicode support, with astral characters
  • International domain support
  • Allows rules extension & custom normalizers



Add it to your project's Gemfile

gem 'linkify-it-rb'

and run bundle install


Add it to your project's Gemfile

gem 'linkify-it-rb'

Edit your Rakefile and add

require 'linkify-it-rb'

and run bundle install

Usage examples

Example 1
linkify =

# Reload full tlds list & add unofficial `.onion` domain.
linkify.tlds('onion', true)      # Add unofficial `.onion` domain
linkify.add('git:', 'http:')     # Add `git:` ptotocol as "alias"
linkify.add('ftp:', null)        # Disable `ftp:` ptotocol
linkify.set({fuzzyIP: true})     # Enable IPs in fuzzy links (without schema)

=> true

=> [#<Linkify::Match @schema="", @index=5, @lastIndex=15, @raw="", @text="", @url="">]
Example 2. Add twitter mentions handler
linkify.add('@', {
  validate: lambda do |text, pos, obj|
    tail = text.slice(pos..-1)
    if (![:twitter])[:twitter] ='^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + LinkifyRe::SRC_Z_P_CC + ')')
    if ([:twitter] =~ tail)
      return 0 if (pos >= 2 && text[pos - 2] == '@')
      return tail.match([:twitter])[0].length
    return 0
  normalize: lambda do |m, obj|
    m.url = '' + m.url.sub(/^@/, '')

API, options)

Creates new linkifier instance with optional additional schemas.

By default understands:

  • http(s)://... , ftp://..., mailto:... & //... links
  • "fuzzy" links and emails (,

schemas is a Hash, where each key/value describes protocol/rule:

  • key - link prefix (usually, protocol name with : at the end, skype: for example). linkify-it-rb makes sure that prefix is not preceded with alphanumeric char.
  • value - rule to check tail after link prefix
    • String - just alias to existing rule
    • Hash
      • validate - validator block (should return matched length on success), or RegExp.
      • normalize - optional block to normalize text & url of matched result (for example, for twitter mentions).


  • fuzzyLink - recognize URL-s without http(s):// head. Default true.
  • fuzzyIP - allow IPs in fuzzy links above. Can conflict with some texts like version numbers. Default false.
  • fuzzyEmail - recognize emails without mailto: prefix. Default true.
  • --- - set true to terminate link with --- (if it's considered as long dash).


Searches linkifiable pattern and returns true on success or false on fail.


Quick check if link MAYBE can exist. Can be used to optimize more expensive .test calls. Return false if link can not be found, true - if .test call needed to know exactly.

.testSchemaAt(text, name, offset)

Similar to .test but checks only specific protocol tail exactly at given position. Returns length of found pattern (0 on fail).


Returns Array of found link matches or nil if nothing found.

Each match has:

  • schema - link schema, can be empty for fuzzy links, or // for protocol-neutral links.
  • index - offset of matched text
  • lastIndex - index of next char after mathch end
  • raw - matched text
  • text - normalized text
  • url - link, generated from matched text

.tlds(list[, keepOld])

Load (or merge) new tlds list. These are needed for fuzzy links (without schema) to avoid false positives. By default this algorithm uses:

  • 2-letter root zones are ok.
  • biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф are ok.
  • encoded (xn--...) root zones are ok.

If that's not enougth, you can reload defaults with more detailed zones list.

.add(schema, definition)

Add new rule with schema prefix. For definition details see constructor description. To disable existing rule use .add(name, nil)


Override default options. Missed properties will not be changed.




Links recognition library used with motion-markdown-it (for Ruby and RubyMotion)





No packages published
You can’t perform that action at this time.