More TAAG Updates

Last night I made two major updates made to the Text Ascii Art Generator:

– A whole crap load of fonts were uploaded, probably between 80 and 100.
– I added some Javascript that converted URLs into hyperlinks in the sections about the FIGlet font authors (the “Click for Info” link). I figured this would be a nice gesture toward the font authors since most people, including myself, are usually too lazy to copy and paste a URL. You can see this script in action in the information section for fonts like “AMC razor 2” and “Sub-Zero”, as well as many others. Alas, after implementing this I discovered most author’s homepages were long gone. Oh well, I still think it’s a nice addition.

To those of you curious as to how this was implemented I used regular expressions. This changed what could have been a lot of code, into one simple line of code! Check it out:

String.prototype.urlsToHyperlinks = function()
{
  return this.replace(/\bhttp:[^ \)\n\<]+/g, “<a href=’$&’ target=’_new’>$&</a>”);
}

And then to use it, do this:

var urlText = “blah blah blah http://www.patorjk.com/ blah blah blah http://www.google.com/”;
var hyperlinkedText = urlText.urlsToHyperlinks();
alert(hyperlinkedText);

Feel free to use this however you want.

If the above code just looked like a bunch of gibberish, don’t worry, regular expressions are easy to pick up. You just need to get the syntax down. Here are some links that should help you get on your feet pretty quickly:

http://www.webreference.com/js/column5/
http://www.javascriptkit.com/javatutors/re.shtml
http://www.w3schools.com/jsref/jsref_replace.asp – Make sure you read example 4. Too many people don’t realize that about the Javascript replace function.