var discoverAndLinkData = (function(){
var discoverAndLinkData = function (plainTextString) {
//International phone numbers are incredibly varied. This is designed to pick up numbers in many regions.
var phoneRegEX = /(\+\s?)?(\(\d{3}\)\s?)?((\d)([-.\s\\\/])?)+\b/g;
var httpRegEX = /\bhttp{1}s?:\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*)+\b/gi;
var emailRegEX = /\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b/gi;
plainTextString = plainTextString.replace(phoneRegEX, function(match,content) {
// For my needs I only really needed to support cell phone calls within the US and UK
// The UK has some very interesting rules and segmenting for calls. Like in the US
// depending on the local provider you can have very short numbers. The 6 digit cut off was
// chosen from empirical evidence that most numbers on the web do not assume the callers
// local region they will give a number that works from outside their area.
if (match.replace(/\D/g, "").length >= 6) {
return "<a href='tel://" + match + "'>" + match + "</a>";
}
return match;
});
//TODO between each match exclude that text from matching again.
plainTextString = plainTextString.replace(emailRegEX, function(match, content) {
return "<a href='mailto:" + match + "'>" + match + "</a>";
});
plainTextString = plainTextString.replace(httpRegEX, function(match, content) {
return "<a href='" + match + "'>" + match + "</a>";
});
return plainTextString;
}
// This was adapted from some
function traverseTextNodes(node, callback) {
var next;
if (node.nodeType === 1) {
// (Element node)
if (node = node.firstChild) {
do {
// Recursively call traverseChildNodes
// on each child node
next = node.nextSibling;
traverseTextNodes(node, callback);
} while(node = next);
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.