-
-
Save bryanjswift/3391111 to your computer and use it in GitHub Desktop.
Revisions
-
bryanjswift revised this gist
Oct 19, 2012 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,20 +14,20 @@ */ define(['underscore'], function(_) { function linkify_entities(tweet) { if (!(tweet.entities)) { return _.escape(tweet.text); } // This is very naive, should find a better way to parse this var index_map = {}; _.each(tweet.entities.urls, function(entry, i) { index_map[entry.indices[0]] = [ entry.indices[1], function(text) { var url = _.escape(entry.url); var t = _.escape(text); return "<a href='" + url + "'>" + t + "</a>"; } ]; }); @@ -36,7 +36,7 @@ define(['underscore'], function(_) { entry.indices[1], function(text) { var et = escape("#"+entry.text); return "<a href='http://twitter.com/search?q=" + et + "'>" + _.escape(text) + "</a>"; } ]; }); @@ -45,9 +45,9 @@ define(['underscore'], function(_) { index_map[entry.indices[0]] = [ entry.indices[1], function(text) { var name = _.escape(entry.name); var sn = _.escape(entry.screen_name); var t = _.escape(text); return "<a title='" + name + "' href='http://twitter.com/" + sn + "'>" + t + "</a>"; } ]; @@ -64,7 +64,7 @@ define(['underscore'], function(_) { var end = ind[0]; var func = ind[1]; if (i > last_i) { result += _.escape(tweet.text.substring(last_i, i)); } result += func(tweet.text.substring(i, end)); i = end - 1; @@ -73,12 +73,12 @@ define(['underscore'], function(_) { } if (i > last_i) { result += _.escape(tweet.text.substring(last_i, i)); } return result; } return linkify_entities; }); -
bryanjswift revised this gist
Oct 19, 2012 . 1 changed file with 36 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,44 +19,61 @@ define(['underscore'], function(_) { } function linkify_entities(tweet) { if (!(tweet.entities)) { return escapeHTML(tweet.text); } // This is very naive, should find a better way to parse this var index_map = {}; _.each(tweet.entities.urls, function(entry, i) { index_map[entry.indices[0]] = [ entry.indices[1], function(text) { return "<a href='"+escapeHTML(entry.url)+"'>"+escapeHTML(text)+"</a>"; } ]; }); _.each(tweet.entities.hashtags, function(entry, i) { index_map[entry.indices[0]] = [ entry.indices[1], function(text) { var et = escape("#"+entry.text); return "<a href='http://twitter.com/search?q=" + et + "'>" + escapeHTML(text) + "</a>"; } ]; }); _.each(tweet.entities.user_mentions, function(entry, i) { index_map[entry.indices[0]] = [ entry.indices[1], function(text) { var name = escapeHTML(entry.name); var sn = escapeHTML(entry.screen_name); var t = escapeHTML(text); return "<a title='" + name + "' href='http://twitter.com/" + sn + "'>" + t + "</a>"; } ]; }); var result = ""; var last_i = 0; var i = 0; // iterate through the string looking for matches in the index_map for (i=0; i < tweet.text.length; ++i) { var ind = index_map[i]; if (ind) { var end = ind[0]; var func = ind[1]; if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)); } result += func(tweet.text.substring(i, end)); i = end - 1; last_i = end; } } if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)); } return result; -
bryanjswift revised this gist
Aug 19, 2012 . 1 changed file with 30 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,31 +10,30 @@ * Licensed under the MIT license * http://wades.im/mons * * Modified by Bryan J Swift to define as AMD module and use underscore.js */ define(['underscore'], function(_) { function escapeHTML(text) { return _.escape(text); } function linkify_entities(tweet) { if (!(tweet.entities)) { return escapeHTML(tweet.text) } // This is very naive, should find a better way to parse this var index_map = {} _.each(tweet.entities.urls, function(entry, i) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a href='"+escapeHTML(entry.url)+"'>"+escapeHTML(text)+"</a>"}] }) _.each(tweet.entities.hashtags, function(entry, i) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a href='http://twitter.com/search?q="+escape("#"+entry.text)+"'>"+escapeHTML(text)+"</a>"}] }) _.each(tweet.entities.user_mentions, function(entry, i) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a title='"+escapeHTML(entry.name)+"' href='http://twitter.com/"+escapeHTML(entry.screen_name)+"'>"+escapeHTML(text)+"</a>"}] }) var result = "" @@ -43,22 +42,26 @@ function linkify_entities(tweet) { // iterate through the string looking for matches in the index_map for (i=0; i < tweet.text.length; ++i) { var ind = index_map[i] if (ind) { var end = ind[0] var func = ind[1] if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)) } result += func(tweet.text.substring(i, end)) i = end - 1 last_i = end } } if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)) } return result; } return linkify_entities; }); -
wadey revised this gist
Jun 17, 2010 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ /* * twitter-entities.js * This function converts a tweet with "entity" metadata * from plain text to linkified HTML. * * See the documentation here: http://dev.twitter.com/pages/tweet_entities * Basically, add ?include_entities=true to your timeline call * * Copyright 2010, Wade Simmons * Licensed under the MIT license -
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ /* * twitter-entities.js * * Copyright 2010, Wade Simmons * Licensed under the MIT license * http://wades.im/mons * * Requires jQuery */ function escapeHTML(text) { return $('<div/>').text(text).html() } function linkify_entities(tweet) { if (!(tweet.entities)) { return escapeHTML(tweet.text) } // This is very naive, should find a better way to parse this var index_map = {} $.each(tweet.entities.urls, function(i,entry) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a href='"+escapeHTML(entry.url)+"'>"+escapeHTML(text)+"</a>"}] }) $.each(tweet.entities.hashtags, function(i,entry) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a href='http://twitter.com/search?q="+escape("#"+entry.text)+"'>"+escapeHTML(text)+"</a>"}] }) $.each(tweet.entities.user_mentions, function(i,entry) { index_map[entry.indices[0]] = [entry.indices[1], function(text) {return "<a title='"+escapeHTML(entry.name)+"' href='http://twitter.com/"+escapeHTML(entry.screen_name)+"'>"+escapeHTML(text)+"</a>"}] }) var result = "" var last_i = 0 var i = 0 // iterate through the string looking for matches in the index_map for (i=0; i < tweet.text.length; ++i) { var ind = index_map[i] if (ind) { var end = ind[0] var func = ind[1] if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)) } result += func(tweet.text.substring(i, end)) i = end - 1 last_i = end } } if (i > last_i) { result += escapeHTML(tweet.text.substring(last_i, i)) } return result }