Merge pull request #4856 from hincupetru/3692-hashtags-inside-markdown-link
Check if the hashtag is a link in function .hashtagify
This commit is contained in:
commit
835608f06f
3 changed files with 29 additions and 5 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
* Show hovercards in the notification drop-down for users on the same pod [#4843](https://github.com/diaspora/diaspora/pull/4843)
|
* Show hovercards in the notification drop-down for users on the same pod [#4843](https://github.com/diaspora/diaspora/pull/4843)
|
||||||
* The photo stream no longer repeats after the last photo [#4726](https://github.com/diaspora/diaspora/issues/4726)
|
* The photo stream no longer repeats after the last photo [#4726](https://github.com/diaspora/diaspora/issues/4726)
|
||||||
* Fix hovercards in the notificaitons dropdown [#4693](https://github.com/diaspora/diaspora/issues/4693)
|
* Fix hovercards in the notificaitons dropdown [#4693](https://github.com/diaspora/diaspora/issues/4693)
|
||||||
|
* Do not parse hashtags inside Markdown links [#3692](https://github.com/diaspora/diaspora/issues/3692)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* You can report a single post by clicking the correct icon in the controler section [#4517](https://github.com/diaspora/diaspora/pull/4517)
|
* You can report a single post by clicking the correct icon in the controler section [#4517](https://github.com/diaspora/diaspora/pull/4517)
|
||||||
|
|
|
||||||
|
|
@ -108,11 +108,15 @@ $(function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
textFormatter.hashtagify = function hashtagify(text){
|
textFormatter.hashtagify = function hashtagify(text){
|
||||||
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g
|
var utf8WordCharcters =/(<a[^>]*>.*?<\/a>)|(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g;
|
||||||
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
|
|
||||||
return preceeder + "<a href='/tags/" + tagText.toLowerCase() +
|
return text.replace(utf8WordCharcters, function(result, linkTag, preceeder, tagText) {
|
||||||
"' class='tag'>#" + tagText + "</a>"
|
if(linkTag)
|
||||||
})
|
return linkTag;
|
||||||
|
else
|
||||||
|
return preceeder + "<a href='/tags/" + tagText.toLowerCase() +
|
||||||
|
"' class='tag'>#" + tagText + "</a>";
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
textFormatter.mentionify = function mentionify(text, mentions) {
|
textFormatter.mentionify = function mentionify(text, mentions) {
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,25 @@ describe("app.helpers.textFormatter", function(){
|
||||||
|
|
||||||
expect(formattedText).toContain("/tags/parties")
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue