diff --git a/lib/oneboxer/twitter_onebox.rb b/lib/oneboxer/twitter_onebox.rb
index 9a8ee8c2f..6da447035 100644
--- a/lib/oneboxer/twitter_onebox.rb
+++ b/lib/oneboxer/twitter_onebox.rb
@@ -24,15 +24,15 @@ module Oneboxer
result['created_at'] =
Time.parse(result['created_at']).strftime("%I:%M%p - %d %b %y")
- result['text'] = link_urls_and_handles_in result['text']
+ result['text'] = link_all_the_things_in result['text']
result
end
private
- def link_urls_and_handles_in(text)
- link_handles_in link_urls_in(text)
+ def link_all_the_things_in(text)
+ link_hashtags_in link_handles_in link_urls_in(text)
end
def link_urls_in(text)
@@ -55,6 +55,19 @@ module Oneboxer
text
end
+ def link_hashtags_in(text)
+ text.scan(/\s#(\w+)/).flatten.uniq.each do |hashtag|
+ text.gsub!("##{hashtag}", [
+ "",
+ "##{hashtag}",
+ ""
+ ].join)
+ end
+
+ text
+ end
+
def tweet_for(id)
request = Net::HTTP::Get.new(tweet_uri_for id)
diff --git a/spec/components/oneboxer/twitter_onebox_spec.rb b/spec/components/oneboxer/twitter_onebox_spec.rb
index 5636f99fa..e0e8d1276 100644
--- a/spec/components/oneboxer/twitter_onebox_spec.rb
+++ b/spec/components/oneboxer/twitter_onebox_spec.rb
@@ -38,6 +38,19 @@ describe Oneboxer::TwitterOnebox do
].join)
end
end
+
+ context 'when the text contains a hashtag' do
+ let(:text) { 'No secrets. #NSA' }
+
+ it 'wraps each hashtag in a link' do
+ expect(subject.parse(data)['text']).to eq([
+ "No secrets. ",
+ "",
+ "#NSA",
+ ""
+ ].join)
+ end
+ end
end
end