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

Add autolink util function to link urls w/o protocol #46

Merged
merged 1 commit into from
Oct 8, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ var validateImageType = function (data, next) {
next(null, true);
};

/**
* Default twitter.autoLink behavior is to _not_ link
* urls without protocol, with no way to override
* https://github.com/twitter/twitter-text-js/blob/master/twitter-text.js#L759
* And: https://github.com/twitter/twitter-text-js/issues/136
*/
var autoLink = function(text, options) {
var entities = twitter.extractEntitiesWithIndices(text, { extractUrlsWithoutProtocol: true });
return twitter.autoLinkEntities(text, entities, options);
};

exports.recent = function (socket) {
publico.getChats(true, function (err, c) {
if (err) {
Expand Down Expand Up @@ -67,7 +78,7 @@ exports.addMessage = function (payload, next) {
return;
}

var message = twitter.autoLink(twitter.htmlEscape(payload.message), {
var message = autoLink(twitter.htmlEscape(payload.message), {
targetBlank: true
});

Expand Down