]> cat aescling's git repositories - mastodon.git/commitdiff
Fix #365, 1/2 of #408 - replace rails_autolink with URI.regexp, run link_hashtags...
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 13:45:09 +0000 (14:45 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 23 Jan 2017 13:45:09 +0000 (14:45 +0100)
Gemfile
Gemfile.lock
app/lib/formatter.rb

diff --git a/Gemfile b/Gemfile
index ebee7e35f1fd9e61347dba183dc7d70aafa6327a..7fb3ab91de1a046c681a06773bb4c9b369f23d04 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -31,7 +31,6 @@ gem 'link_header'
 gem 'ostatus2'
 gem 'goldfinger'
 gem 'devise'
-gem 'rails_autolink'
 gem 'doorkeeper'
 gem 'rabl'
 gem 'oj'
index 0e720d7fb9d3aef5fd4d08e912c5c27c3447a18f..12f6679c7fe4d3a84ad48c673005be712b705bb0 100644 (file)
@@ -268,8 +268,6 @@ GEM
     rails_12factor (0.0.3)
       rails_serve_static_assets
       rails_stdout_logging
-    rails_autolink (1.1.6)
-      rails (> 3.1)
     rails_serve_static_assets (0.0.5)
     rails_stdout_logging (0.0.5)
     railties (5.0.1)
@@ -456,7 +454,6 @@ DEPENDENCIES
   rails (~> 5.0.1.0)
   rails-settings-cached
   rails_12factor
-  rails_autolink
   react-rails
   redis (~> 3.2)
   redis-rails
index 04386d295a3918ebc8b452a030cab7f4104757ef..3565611bc9c4985f86d848c65ab0645765022399 100644 (file)
@@ -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>"