mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: twitter onebox keeps whitespace for expanded links (#17055)
This commit is contained in:
@ -96,15 +96,17 @@ class TwitterApi
|
|||||||
|
|
||||||
def link_handles_in(text)
|
def link_handles_in(text)
|
||||||
text.gsub(/(?:^|\s)@\w+/) do |match|
|
text.gsub(/(?:^|\s)@\w+/) do |match|
|
||||||
handle = match.strip[1..]
|
whitespace = match[0] == " " ? " " : ""
|
||||||
"<a href='https://twitter.com/#{handle}' target='_blank'>@#{handle}</a>"
|
handle = match.strip[1..]
|
||||||
|
"#{whitespace}<a href='https://twitter.com/#{handle}' target='_blank'>@#{handle}</a>"
|
||||||
end.strip
|
end.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def link_hashtags_in(text)
|
def link_hashtags_in(text)
|
||||||
text.gsub(/(?:^|\s)#\w+/) do |match|
|
text.gsub(/(?:^|\s)#\w+/) do |match|
|
||||||
hashtag = match.strip[1..]
|
whitespace = match[0] == " " ? " " : ""
|
||||||
"<a href='https://twitter.com/search?q=%23#{hashtag}' target='_blank'>##{hashtag}</a>"
|
hashtag = match.strip[1..]
|
||||||
|
"#{whitespace}<a href='https://twitter.com/search?q=%23#{hashtag}' target='_blank'>##{hashtag}</a>"
|
||||||
end.strip
|
end.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user