Javascript でオートリンク

var simpleHTML = function(value) {
    var html = "";
    var re = /((http|https|ftp):\/\/[\w\!?=&.\/-;#~%-]+)/g;
    var htmlTemp = escapeHTML(value).replace(/ /g, "<nbsp\/>");
    var matchLinks = value.match(re);
    var n1, n2, i, len;
    if (matchLinks) {
        for (i = 0, len=matchLinks.length; i < len; i++) {
            htmlTemp = htmlTemp.replace(escapeHTML(matchLinks[i]), '<url' + i + '>');
        }
        for (i = 0, len=matchLinks.length; i < len; i++) {
            n1 = matchLinks[i];
            n2 = wrapLongText(n1);
            htmlTemp = htmlTemp.replace('<url' + i + '>', '<a target="_blank" href="' + n1 + '">' + n2 + '<\/a>');
        }
    }

    var lines = htmlTemp.replace(/\r\n/g,"\n").replace(/\r/g,"\n").replace(/<nbsp\/>/g, "&nbsp;")
        .split("\n");

    var size = lines.length;
    for (var i = 0; i < size; i++) {
        html += lines[i];
        html += "<br\/>";
    }
    return html;
};