|
|
@ -48,6 +48,26 @@ class TextFormatter
|
|
|
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
|
|
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
include ERB::Util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def shortened_link(url, rel_me: false)
|
|
|
|
|
|
|
|
url = Addressable::URI.parse(url).to_s
|
|
|
|
|
|
|
|
rel = rel_me ? (DEFAULT_REL + %w(me)) : DEFAULT_REL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix = url.match(URL_PREFIX_REGEX).to_s
|
|
|
|
|
|
|
|
display_url = url[prefix.length, 30]
|
|
|
|
|
|
|
|
suffix = url[prefix.length + 30..-1]
|
|
|
|
|
|
|
|
cutoff = url[prefix.length..-1].length > 30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<~HTML.squish
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
HTML
|
|
|
|
|
|
|
|
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
|
|
|
|
|
|
|
h(url)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
def rewrite
|
|
|
|
def rewrite
|
|
|
@ -70,19 +90,7 @@ class TextFormatter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def link_to_url(entity)
|
|
|
|
def link_to_url(entity)
|
|
|
|
url = Addressable::URI.parse(entity[:url]).to_s
|
|
|
|
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
|
|
|
|
rel = with_rel_me? ? (DEFAULT_REL + %w(me)) : DEFAULT_REL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix = url.match(URL_PREFIX_REGEX).to_s
|
|
|
|
|
|
|
|
display_url = url[prefix.length, 30]
|
|
|
|
|
|
|
|
suffix = url[prefix.length + 30..-1]
|
|
|
|
|
|
|
|
cutoff = url[prefix.length..-1].length > 30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<~HTML.squish
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
HTML
|
|
|
|
|
|
|
|
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
|
|
|
|
|
|
|
h(entity[:url])
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def link_to_hashtag(entity)
|
|
|
|
def link_to_hashtag(entity)
|
|
|
|