diff --git a/lib/twitter_api.rb b/lib/twitter_api.rb index 85155dd2e3a..f8d9fd71dcc 100644 --- a/lib/twitter_api.rb +++ b/lib/twitter_api.rb @@ -96,15 +96,17 @@ class TwitterApi def link_handles_in(text) text.gsub(/(?:^|\s)@\w+/) do |match| - handle = match.strip[1..] - "@#{handle}" + whitespace = match[0] == " " ? " " : "" + handle = match.strip[1..] + "#{whitespace}@#{handle}" end.strip end def link_hashtags_in(text) text.gsub(/(?:^|\s)#\w+/) do |match| - hashtag = match.strip[1..] - "##{hashtag}" + whitespace = match[0] == " " ? " " : "" + hashtag = match.strip[1..] + "#{whitespace}##{hashtag}" end.strip end