A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://markdown-it.github.io/linkify-it/doc/ below:

linkify-it 5.0.0 API documentation

linkify-it

Links recognition library with FULL unicode support. Focused on high quality link patterns detection in plain text.

Demo

Why it's awesome:

Install
npm install linkify-it --save

Browserification is also supported.

Usage examples Example 1
import linkifyit from 'linkify-it';
const linkify = linkifyit();


linkify
  .tlds(require('tlds'))          
  .tlds('onion', true)            
  .add('git:', 'http:')           
  .add('ftp:', null)              
  .set({ fuzzyIP: true });        

console.log(linkify.test('Site github.com!'));  

console.log(linkify.match('Site github.com!')); 
                                                
                                                
                                                
                                                
                                                
                                                
                                                
Example 2. Add twitter mentions handler
linkify.add('@', {
  validate: function (text, pos, self) {
    const tail = text.slice(pos);

    if (!self.re.twitter) {
      self.re.twitter =  new RegExp(
        '^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self.re.src_ZPCc + ')'
      );
    }
    if (self.re.twitter.test(tail)) {
      
      
      if (pos >= 2 && tail[pos - 2] === '@') {
        return false;
      }
      return tail.match(self.re.twitter)[0].length;
    }
    return 0;
  },
  normalize: function (match) {
    match.url = 'https://twitter.com/' + match.url.replace(/^@/, '');
  }
});
API

API documentation

new LinkifyIt(schemas, options)

Creates new linkifier instance with optional additional schemas. Can be called without new keyword for convenience.

By default understands:

schemas is an object, where each key/value describes protocol/rule:

options:

.test(text)

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

.pretest(text)

Quick check if link MAY BE 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).

.match(text)

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

Each match has:

.matchAtStart(text)

Checks if a match exists at the start of the string. Returns Match (see docs for match(text)) or null if no URL is at the start. Doesn't work with fuzzy links.

.tlds(list[, keepOld])

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

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

.add(key, value)

Add a new schema to the schemas object. As described in the constructor definition, key is a link prefix (skype:, for example), and value is a String to alias to another schema, or an Object with validate and optionally normalize definitions. To disable an existing rule, use .add(key, null).

.set(options)

Override default options. Missed properties will not be changed.

License

MIT

LinkifyIt LinkifyIt.new

Creates new linkifier instance with optional additional schemas. Can be called without new keyword for convenience.

By default understands:

schemas is an object, where each key/value describes protocol/rule:

options:

LinkifyIt#add

chainable

Add new rule definition. See constructor description for details.

LinkifyIt#match

Returns array of found link descriptions or null on fail. We strongly recommend to use LinkifyIt#test first, for best speed.

Result match description LinkifyIt#matchAtStart

Returns fully-formed (not fuzzy) link if it starts at the beginning of the string, and null otherwise.

LinkifyIt#normalize

Default normalizer (if schema does not define it's own).

LinkifyIt#onCompile

Override to modify basic RegExp-s.

LinkifyIt#pretest

Very quick check, that can give false positives. Returns true if link MAY BE can exists. Can be used for speed optimization, when you need to check that link NOT exists.

LinkifyIt#set

chainable

Set recognition options for links without schema.

LinkifyIt#test

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

LinkifyIt#testSchemaAt

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

LinkifyIt#tlds

chainable

Load (or merge) new tlds list. Those are user for fuzzy links (without prefix) to avoid false positives. By default this algorythm used:

If list is replaced, then exact match for 2-chars root zones will be checked.

Match Description

Match result. Single element of array, returned by LinkifyIt#match

Match#index

First position of matched string.

Match#lastIndex

Next position after matched string.

Match#raw

Matched string.

Match#schema

Prefix (protocol) for matched string.

Match#text

Notmalized text of matched string.

Match#url

Normalized url of matched string.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4