Skip to content
Extraits de code Groupes Projets
Valider 694dc7d8 rédigé par Hincu Petru's avatar Hincu Petru
Parcourir les fichiers

Check if the hashtag is a link in function .hashtagify

parent a51c4f0d
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -108,11 +108,15 @@ $(function() {
};
textFormatter.hashtagify = function hashtagify(text){
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
return preceeder + "<a href='/tags/" + tagText.toLowerCase() +
"' class='tag'>#" + tagText + "</a>"
})
var utf8WordCharcters =/(<a[^>]*>.*?<\/a>)|(\s|^|>)#([\u0080-\uFFFF|\w|-]+|&lt;3)/g;
return text.replace(utf8WordCharcters, function(result, linkTag, preceeder, tagText) {
if(linkTag)
return linkTag;
else
return preceeder + "<a href='/tags/" + tagText.toLowerCase() +
"' class='tag'>#" + tagText + "</a>";
});
};
textFormatter.mentionify = function mentionify(text, mentions) {
......
......@@ -238,6 +238,25 @@ describe("app.helpers.textFormatter", function(){
expect(formattedText).toContain("/tags/parties")
})
it("doesn't create tag if the text is a link", function(){
var tags = ['diaspora', 'twitter', 'hrabrahabr'];
var text = $('<a/>', { href: 'http://me.co' }).html('#me')[0].outerHTML;
_.each(tags, function(tagName){
text += ' #'+tagName+',';
});
text += 'I love';
var formattedText = this.formatter.hashtagify(text);
var wrapper = $('<div>').html(formattedText);
expect(wrapper.find("a[href='http://me.co']").text()).toContain('#me');
_.each(tags, function(tagName){
expect(wrapper.find("a[href='/tags/"+tagName+"']").text()).toContain('#'+tagName);
});
})
})
})
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter