Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: twitter/twitter-text-js
...
head fork: twitter/twitter-text-js
Checking mergeability… Don't worry, you can still create the pull request.
  • 16 commits
  • 2 files changed
  • 0 commit comments
  • 6 contributors
Commits on Mar 29, 2012
Jacob Hoffman-Andrews Fix text-hiding technique to be compatible with IE7, and set linkText…
… to displayUrl when displayUrl is not a substring of expandedUrl (i.e. pic.twitter.com links)
c770d03
Jacob Hoffman-Andrews Make invisibleTagAttrs a user-settable options
11ff789
Jacob Hoffman-Andrews Add tests for pic.twitter.com autolinking and invisibleTagAttrs
09cf779
Commits on Mar 31, 2012
@tomykaira tomykaira Fix atSign to atSigns
cf51da9
@tomykaira tomykaira Upgraded to the latest conformance suite
5d00d3d
Commits on Apr 02, 2012
@keitaf keitaf Merge pull request #56 from tomykaira/fix_spell_miss
Fix spell miss
87e67c8
Commits on Apr 03, 2012
@keitaf keitaf Merge pull request #53 from twitter/fix_urlentities
Fix text-hiding technique to be compatible with IE7, and set linkText to...
24c5136
Commits on Apr 16, 2012
@kscanne kscanne Add combining diacritics to hashtags
0b80555
Commits on May 02, 2012
@keitaf keitaf Merge pull request #57 from kscanne/combining_chars_in_hashtags
Add combining diacritics to hashtags
2f0043e
@keitaf keitaf Merge branch 'master' of github.com:twitter/twitter-text-js into use_…
…displayurl_in_entity

Conflicts:
	twitter-text.js
e5c95ce
@keitaf keitaf Upgraded to the latest conformance suite
c9946a6
@keitaf keitaf pass options from linkToUrl() to linkTextWithEntity()
c6db895
@keitaf keitaf modify unit test to correctly verify that expanded URL is used as a t…
…itle but its tail is not included in the body text
b4bbc0d
@keitaf keitaf add unit tests for linkTextWithEntity()
fcd597e
Commits on May 05, 2012
@couch couch Merge pull request #54 from twitter/use_displayurl_in_entity
Modify linkToUrl() to use display_url and expanded_url in the input entity, add unit tests for new linkTextWithEntity() function.
87ca503
Commits on May 18, 2012
@keitaf keitaf Merge branch 'master' of github.com:twitter/twitter-text-js into add_…
…autolink_json
d41a146
Showing with 64 additions and 5 deletions.
  1. +56 −0 test/tests.js
  2. +8 −5 twitter-text.js
View
56 test/tests.js
@@ -125,6 +125,7 @@ test("twttr.txt.autolink", function() {
// url entities
var autoLinkResult = twttr.txt.autoLink("http://t.co/0JG5Mcq", {
+ invisibleTagAttrs: "style='font-size:0'",
urlEntities: [{
"url": "http://t.co/0JG5Mcq",
"display_url": "blog.twitter.com/2011/05/twitte…",
@@ -139,6 +140,7 @@ test("twttr.txt.autolink", function() {
ok(autoLinkResult.match(/>blog.twitter.com\/2011\/05\/twitte.*…</), 'Use display url from url entities');
ok(autoLinkResult.match(/r-for-mac-update.html</), 'Include the tail of expanded_url');
ok(autoLinkResult.match(/>http:\/\//), 'Include the head of expanded_url');
+ ok(autoLinkResult.match(/span style='font-size:0'/), 'Obey invisibleTagAttrs');
autoLinkResult = twttr.txt.autoLinkEntities("http://t.co/0JG5Mcq",
[{
@@ -162,6 +164,22 @@ test("twttr.txt.autolink", function() {
ok(range.toString().match(/\shttp:\/\/blog.twitter.com\/2011\/05\/twitter-for-mac-update.html\s/), 'Selection copies expanded_url');
document.body.removeChild(div);
+ var picTwitter = twttr.txt.autoLink("http://t.co/0JG5Mcq", {
+ urlEntities: [{
+ "url": "http://t.co/0JG5Mcq",
+ "display_url": "pic.twitter.com/xyz",
+ "expanded_url": "http://twitter.com/foo/statuses/123/photo/1",
+ "indices": [
+ 84,
+ 103
+ ]
+ }]
+ });
+ ok(picTwitter.match(/<a href="http:\/\/t.co\/0JG5Mcq"[^>]+>/), 'Use t.co URL as link target');
+ ok(picTwitter.match(/>pic.twitter.com\/xyz</), 'Use display url from url entities');
+ ok(picTwitter.match(/title="http:\/\/twitter.com\/foo\/statuses\/123\/photo\/1"/), 'Use expanded url as title');
+ ok(!picTwitter.match(/foo\/statuses</), 'Don\'t include the tail of expanded_url');
+
// urls with invalid character
var invalidChars = ['\u202A', '\u202B', '\u202C', '\u202D', '\u202E'];
for (var i = 0; i < invalidChars.length; i++) {
@@ -173,6 +191,44 @@ test("twttr.txt.autolink", function() {
"Autolink hashtag/mentionURL w/ Supplementary character");
});
+test("twttr.txt.linkTextWithEntity", function() {
+ var result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "twitter.com",
+ "expanded_url": "http://twitter.com/"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/</span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span>",
+ "Entire display_url is in expanded_url");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "twitter.com…",
+ "expanded_url": "http://twitter.com/abcdefg"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span><span class='invisible'>http://</span><span class='js-display-url'>twitter.com</span><span class='invisible'>/abcdefg</span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span>…</span>",
+ "display_url ends with …");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "…tter.com/abcdefg",
+ "expanded_url": "http://twitter.com/abcdefg"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "<span class='tco-ellipsis'>…<span class='invisible'>&nbsp;</span></span><span class='invisible'>http://twi</span><span class='js-display-url'>tter.com/abcdefg</span><span class='invisible'></span><span class='tco-ellipsis'><span class='invisible'>&nbsp;</span></span>",
+ "display_url begins with …");
+
+ result = twttr.txt.linkTextWithEntity({
+ "url": "http://t.co/abcde",
+ "display_url": "pic.twitter.com/xyz",
+ "expanded_url": "http://twitter.com/foo/statuses/123/photo/1"},
+ {invisibleTagAttrs: "class='invisible'"});
+ same(result,
+ "pic.twitter.com/xyz",
+ "display_url and expanded_url are on different domains");
+});
+
test("twttr.txt.extractMentionsOrListsWithIndices", function() {
var invalid_chars = ['!', '@', '#', '$', '%', '&', '*'];
View
13 twitter-text.js
@@ -194,6 +194,8 @@ if (typeof twttr === "undefined" || twttr === null) {
addCharsToCharClass(latinAccentChars, 0x028b, 0x028b);
// Okina for Hawaiian (it *is* a letter character)
addCharsToCharClass(latinAccentChars, 0x02bb, 0x02bb);
+ // Combining diacritics
+ addCharsToCharClass(latinAccentChars, 0x0300, 0x036f);
// Latin Extended Additional
addCharsToCharClass(latinAccentChars, 0x1e00, 0x1eff);
twttr.txt.regexen.latinAccentChars = regexSupplant(latinAccentChars.join(""));
@@ -447,7 +449,7 @@ if (typeof twttr === "undefined" || twttr === null) {
if (!options.title) {
options.htmlAttrs = (options.htmlAttrs || "") + " title=\"" + urlEntity.expanded_url + "\"";
}
- linkText = twttr.txt.linkTextWithEntity(urlEntity);
+ linkText = twttr.txt.linkTextWithEntity(urlEntity, options);
}
var d = {
@@ -459,7 +461,7 @@ if (typeof twttr === "undefined" || twttr === null) {
return stringSupplant("<a href=\"#{url}\"#{htmlAttrs}>#{linkText}</a>", d);
};
- twttr.txt.linkTextWithEntity = function (entity) {
+ twttr.txt.linkTextWithEntity = function (entity, options) {
var displayUrl = entity.display_url;
var expandedUrl = entity.expanded_url;
@@ -520,10 +522,10 @@ if (typeof twttr === "undefined" || twttr === null) {
// <span style='font-size:0'>&nbsp;</span>
// …
// </span>
- v['invisible'] = "style='font-size:0; line-height:0'";
+ v['invisible'] = options.invisibleTagAttrs;
return stringSupplant("<span class='tco-ellipsis'>#{precedingEllipsis}<span #{invisible}>&nbsp;</span></span><span #{invisible}>#{beforeDisplayUrl}</span><span class='js-display-url'>#{displayUrlSansEllipses}</span><span #{invisible}>#{afterDisplayUrl}</span><span class='tco-ellipsis'><span #{invisible}>&nbsp;</span>#{followingEllipsis}</span>", v);
}
- return dispalyUrl;
+ return displayUrl;
};
twttr.txt.autoLinkEntities = function(text, entities, options) {
@@ -544,6 +546,7 @@ if (typeof twttr === "undefined" || twttr === null) {
options.listUrlBase = options.listUrlBase || "https://twitter.com/";
options.before = options.before || "";
options.htmlAttrs = twttr.txt.extractHtmlAttrsFromOptions(options);
+ options.invisibleTagAttrs = options.invisibleTagAttrs || "style='position:absolute;left:-9999px;'";
// remap url entities to hash
var urlEntities, i, len;
@@ -696,7 +699,7 @@ if (typeof twttr === "undefined" || twttr === null) {
* (Presence of listSlug indicates a list)
*/
twttr.txt.extractMentionsOrListsWithIndices = function(text) {
- if (!text || !text.match(twttr.txt.regexen.atSign)) {
+ if (!text || !text.match(twttr.txt.regexen.atSigns)) {
return [];
}

No commit comments for this range

Something went wrong with that request. Please try again.