title: How to post-process HTML to add "target blank" to all links in Ruby?
body: <p>How to post-process HTML to add "target blank" to all links in Ruby?</p>
  
  <p>I am currently using Rinku (gem) to auto-link text, and that works great. </p>
  
  <p>However, I am post-processing HTML and some links are already links, and therefore are not processed with Rinku.</p>
  
  <p>How could I add the target blank attribute to those?</p>
  
  <p>application_controller.rb</p>
  
  <pre><code>def text_renderer text
    AutoHTML.new(text).render
  end
  </code></pre>
  
  <p>auto_html.rb</p>
  
  <pre><code>class AutoHTML
    include ActionView::Helpers
  
    def initialize text
      @text = text
    end
  
    def render
      text = prepare @text
      text = auto_link(text)
      text.html_safe
    end
  
    private
  
    def prepare text
      if text.nil? || text.empty?
        ""
      else
        text
      end
    end
  
    def auto_link text
      Rinku.auto_link(text, :all, 'target="_blank"')
    end
  end
  </code></pre>