1

I use Redcarpet as my backend Markdown interpreter solution.

I want all links to have a html target attribute and its value equal to '_blank', but I can't find any solution for it.

Could any one help me? Thanks.

charlysisto
  • 3,700
  • 17
  • 30
user3087000
  • 731
  • 1
  • 13
  • 24

3 Answers3

2

Although I don't know specifically how to do this, I would look at using a custom renderer:

#app/lib/blank_targets.rb
class BlankTargets < Redcarpet::Render::HTML
  def link(link, title, content)
    #custom code here
  end
end

#Your Controller
markdown = Redcarpet::Markdown.new(BlankTargets)
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
2

They've since introduced a new option, which you can use like so:

link_attributes: { target: '_blank' }
David
  • 167
  • 2
  • 10
0

Finally I write JavaScript to handle it...

I think this is the fastest way....

user3087000
  • 731
  • 1
  • 13
  • 24