|
|
|
|
@ -33,8 +33,6 @@ class TextFormatter
|
|
|
|
|
def to_s
|
|
|
|
|
return ''.html_safe if text.blank?
|
|
|
|
|
|
|
|
|
|
html = nil
|
|
|
|
|
MastodonOTELTracer.in_span('TextFormatter#to_s extract_and_rewrite') do
|
|
|
|
|
html = rewrite do |entity|
|
|
|
|
|
if entity[:url]
|
|
|
|
|
link_to_url(entity)
|
|
|
|
|
@ -44,13 +42,8 @@ class TextFormatter
|
|
|
|
|
link_to_mention(entity)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if multiline?
|
|
|
|
|
MastodonOTELTracer.in_span('TextFormatter#to_s simple_format') do
|
|
|
|
|
html = simple_format(html, {}, sanitize: false).delete("\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
html = simple_format(html, {}, sanitize: false).delete("\n") if multiline?
|
|
|
|
|
|
|
|
|
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
|
|
|
|
end
|
|
|
|
|
@ -106,13 +99,10 @@ class TextFormatter
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_url(entity)
|
|
|
|
|
MastodonOTELTracer.in_span('TextFormatter#link_to_url') do
|
|
|
|
|
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_hashtag(entity)
|
|
|
|
|
MastodonOTELTracer.in_span('TextFormatter#link_to_hashtag') do
|
|
|
|
|
hashtag = entity[:hashtag]
|
|
|
|
|
url = tag_url(hashtag)
|
|
|
|
|
|
|
|
|
|
@ -120,10 +110,8 @@ class TextFormatter
|
|
|
|
|
<a href="#{h(url)}" class="mention hashtag" rel="tag">#<span>#{h(hashtag)}</span></a>
|
|
|
|
|
HTML
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def link_to_mention(entity)
|
|
|
|
|
MastodonOTELTracer.in_span('TextFormatter#link_to_mention') do
|
|
|
|
|
username, domain = entity[:screen_name].split('@')
|
|
|
|
|
domain = nil if local_domain?(domain)
|
|
|
|
|
account = nil
|
|
|
|
|
@ -154,7 +142,6 @@ class TextFormatter
|
|
|
|
|
<span class="h-card" translate="no"><a href="#{h(url)}" class="u-url mention">@<span>#{h(display_username)}</span></a></span>
|
|
|
|
|
HTML
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def entity_cache
|
|
|
|
|
@entity_cache ||= EntityCache.instance
|
|
|
|
|
|