diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-01-23 14:45:09 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-01-23 14:45:09 +0100 |
commit | d4d56b8af0e85e328eb1a323816d734ca16a4176 (patch) | |
tree | b2a307d9712e9dcd8af31f994f793c82455c70d1 /app | |
parent | aa9c51a34c4ca226a68f7116573bc37cd172c8f6 (diff) |
Fix #365, 1/2 of #408 - replace rails_autolink with URI.regexp, run link_hashtags on simplified_format
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/formatter.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 04386d295..3565611bc 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -32,6 +32,7 @@ class Formatter html = encode(account.note) html = link_urls(html) + html = link_hashtags(html) html.html_safe # rubocop:disable Rails/OutputSafety end @@ -43,8 +44,8 @@ class Formatter end def link_urls(html) - auto_link(html, link: :urls, html: { rel: 'nofollow noopener', target: '_blank' }) do |text| - truncate(text.gsub(/\Ahttps?:\/\/(www\.)?/, ''), length: 30) + html.gsub(URI.regexp(%w(http https))) do |match| + link_html(match) end end @@ -63,6 +64,11 @@ class Formatter 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) prefix, affix = match.split('#') "#{prefix}<a href=\"#{tag_url(affix.downcase)}\" class=\"mention hashtag\">#<span>#{affix}</span></a>" |