mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-25 12:34:58 +01:00
Use rails built-in tag
methods in TextFormatter.shortened_link
(#28976)
This commit is contained in:
parent
7e6eb64f1e
commit
2c0441acd7
@ -50,6 +50,7 @@ class TextFormatter
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
include ERB::Util
|
include ERB::Util
|
||||||
|
include ActionView::Helpers::TagHelper
|
||||||
|
|
||||||
def shortened_link(url, rel_me: false)
|
def shortened_link(url, rel_me: false)
|
||||||
url = Addressable::URI.parse(url).to_s
|
url = Addressable::URI.parse(url).to_s
|
||||||
@ -60,9 +61,11 @@ class TextFormatter
|
|||||||
suffix = url[prefix.length + 30..]
|
suffix = url[prefix.length + 30..]
|
||||||
cutoff = url[prefix.length..].length > 30
|
cutoff = url[prefix.length..].length > 30
|
||||||
|
|
||||||
<<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety
|
tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do
|
||||||
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
|
tag.span(prefix, class: 'invisible') +
|
||||||
HTML
|
tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) +
|
||||||
|
tag.span(suffix, class: 'invisible')
|
||||||
|
end
|
||||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||||
h(url)
|
h(url)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user