FIX: twitter onebox keeps whitespace for expanded links (#17055)

This commit is contained in:
Gabe Pacuilla 2022-06-10 01:20:26 -04:00 committed by GitHub
parent ced9a5ee6d
commit c04cb223f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,15 +96,17 @@ class TwitterApi
def link_handles_in(text)
text.gsub(/(?:^|\s)@\w+/) do |match|
handle = match.strip[1..]
"<a href='https://twitter.com/#{handle}' target='_blank'>@#{handle}</a>"
whitespace = match[0] == " " ? " " : ""
handle = match.strip[1..]
"#{whitespace}<a href='https://twitter.com/#{handle}' target='_blank'>@#{handle}</a>"
end.strip
end
def link_hashtags_in(text)
text.gsub(/(?:^|\s)#\w+/) do |match|
hashtag = match.strip[1..]
"<a href='https://twitter.com/search?q=%23#{hashtag}' target='_blank'>##{hashtag}</a>"
whitespace = match[0] == " " ? " " : ""
hashtag = match.strip[1..]
"#{whitespace}<a href='https://twitter.com/search?q=%23#{hashtag}' target='_blank'>##{hashtag}</a>"
end.strip
end