user3087000
user3087000

Reputation: 751

Rails - Use Redcarpet as Markdown interpreter, how can I make all links have a html targer _blank attribute?

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.

Upvotes: 1

Views: 617

Answers (3)

David
David

Reputation: 167

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

link_attributes: { target: '_blank' }

Upvotes: 2

user3087000
user3087000

Reputation: 751

Finally I write JavaScript to handle it...

I think this is the fastest way....

Upvotes: 0

Richard Peck
Richard Peck

Reputation: 76784

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)

Upvotes: 2

Related Questions