|
|
@ -32,6 +32,7 @@ class Formatter
|
|
|
|
|
|
|
|
|
|
|
|
html = encode(account.note)
|
|
|
|
html = encode(account.note)
|
|
|
|
html = link_urls(html)
|
|
|
|
html = link_urls(html)
|
|
|
|
|
|
|
|
html = link_hashtags(html)
|
|
|
|
|
|
|
|
|
|
|
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
|
|
|
html.html_safe # rubocop:disable Rails/OutputSafety
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -43,8 +44,8 @@ class Formatter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def link_urls(html)
|
|
|
|
def link_urls(html)
|
|
|
|
auto_link(html, link: :urls, html: { rel: 'nofollow noopener', target: '_blank' }) do |text|
|
|
|
|
html.gsub(URI.regexp(%w(http https))) do |match|
|
|
|
|
truncate(text.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30)
|
|
|
|
link_html(match)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -63,6 +64,11 @@ class Formatter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def link_html(url)
|
|
|
|
|
|
|
|
link_text = truncate(url.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30)
|
|
|
|
|
|
|
|
"<a rel=\"nofollow noopener\" target=\"_blank\" href=\"#{url}\">#{link_text}</a>"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def hashtag_html(match)
|
|
|
|
def hashtag_html(match)
|
|
|
|
prefix, affix = match.split('#')
|
|
|
|
prefix, affix = match.split('#')
|
|
|
|
"#{prefix}<a href=\"#{tag_url(affix.downcase)}\" class=\"mention hashtag\">#<span>#{affix}</span></a>"
|
|
|
|
"#{prefix}<a href=\"#{tag_url(affix.downcase)}\" class=\"mention hashtag\">#<span>#{affix}</span></a>"
|
|
|
|