mirror of
https://github.com/discourse/discourse.git
synced 2025-04-17 09:39:03 +08:00
FIX: twitter onebox keeps whitespace for expanded links (#17055)
This commit is contained in:
parent
ced9a5ee6d
commit
c04cb223f3
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user