Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Atuo-detect urls
Browse files Browse the repository at this point in the history
  • Loading branch information
depado committed Dec 3, 2014
1 parent 54c6b84 commit 8086cc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var express = require('express'),
validator = require('validator'),
compress = require('compression'),
staticData = require('./static_data'),
generation = require('./generation');
generation = require('./generation'),
validUrl = require('valid-url');

// Nunjucks configuration
nunjucks.configure('views', {
Expand Down Expand Up @@ -53,6 +54,13 @@ io.sockets.on('connection', function (socket) {
data = data.replace(re, generation.generate_img_string(key));
}
};
var arr = data.split(" ");
for (var i=0; i<arr.length; i++) {
if (validUrl.isUri(arr[i])){
arr[i] = "<a href='" + arr[i] + "''>" + arr[i] + "</a>";
}
}
data = arr.join(" ");
io.sockets.emit('updatechat', socket.username, data);
break;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"express": "^4.2.0",
"nunjucks": "^1.0.5",
"socket.io": "^0.9.16",
"valid-url": "^1.0.9",
"validator": "^3.12.0"
},
"devDependencies": {},
Expand Down

0 comments on commit 8086cc9

Please sign in to comment.