/anchorme.js

Javascript function to convert URLs in text to clickable HTML anchor links

Primary LanguageHTMLMIT LicenseMIT

Anchorme.js v0.4.1

Javascript library to convert URLs in text to clickable HTML anchor links.

Creates links for

  • URLs
  • IPs
  • Emails

Features:

  1. Highly sensitive.
  2. Least possible false positives with high sensitivity.
  3. Skips HTML (won't break it if it had a URL as an attribute of some element).
  4. Would make links if they have protocols (eg. http://) or not.
  5. Supports all TLDs in accordance to an up-to-date IANA list.
  6. Also works with IPs, FTPs, and Emails.
  7. Also works when ports defined (eg. mywebsite:80/page.html)
  8. you can set any attribute you want for the resulting elements
  9. Very small in size (Minified version: 14KB).
  10. No regex involved, very readable and maintainable
  11. Higher performance than similar libraries.
  12. Tested against Autolinker.js and linkifyjs on FireFox and proved competitive perforamnce. You can compare it yourself in the demo page.

How to use:

A. include the library file in your HTML:

<script type="text/javascript" src="anchorme.min.js"></script>

B. call the method:

var someText = "this is a text with a link www.github.com ..";
var result = anchorme.js(someText);

C. [OPTIONAL] Set any attribute you want like this:

var someText = "this is a text with a link www.github.com ..";
var result = anchorme.js(someText,{"class":"someclassname","id":"someID","target":"_blank", "attribute-name":"attribute-property"});

Test it before using..

Check how this libary would work for you here