From 7c4d783d51d8a5ef9b4b97ad16b5915d650994b6 Mon Sep 17 00:00:00 2001 From: Hincu Petru Date: Thu, 13 Mar 2014 21:39:12 +0000 Subject: [PATCH] Check if the hashtag is a link in function .hashtagify --- .../javascripts/app/helpers/text_formatter.js | 15 ++++++++++----- .../app/helpers/text_formatter_spec.js | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index 3e122d87a..0ae8e9d5d 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -108,11 +108,16 @@ $(function() { }; textFormatter.hashtagify = function hashtagify(text){ - var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g - return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) { - return preceeder + "#" + tagText + "" - }) + var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g; + var linkRegex = /]*>(.*?)<\/a>/g; + + if(text.match(linkRegex)) + return text; + else + return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) { + return preceeder + "#" + tagText + "" + }); }; textFormatter.mentionify = function mentionify(text, mentions) { diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 29aec511e..2c1461b69 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -238,6 +238,13 @@ describe("app.helpers.textFormatter", function(){ expect(formattedText).toContain("/tags/parties") }) + + it("doesn't create tag if the text is a link", function(){ + var link = $('', { href: 'http://me.co' }).html('#me')[0].outerHTML; + var result = this.formatter.hashtagify(link); + + expect(result).toEqual(link); + }) }) })