railsのredcarpetを利用してマークダウンを利用しています。
link_attributesでリンクを別ウィンドウで開きたいのですが、対応できない為
どなたかご教授いただければと存じます。
dashboards_helper.rb
ruby
1 def markdown(text) 2 html_render = HTMLwithCoderay.new() 3 options = { 4 autolink: true, 5 space_after_headers: true, 6 fenced_code_blocks: true, 7 tables: true, 8 hard_wrap: true, 9 lax_html_blocks: true, 10 strikethrough: true, 11 link_attributes: { rel: 'nofollow', target: "_blank" }, 12 with_toc_data: true 13 } 14 15 markdown = Redcarpet::Markdown.new(html_render, options) 16 markdown.render(text) 17 end
show.html.slim
ruby
1 div = markdown(@article.content).html_safe
▲やりたい事▲
マークダウン
html
1[hoge](http://example.com){: target="_blank"}
htmlへ変換された内容
<a target="_blank" href="http://example.com">hoge</a>
■現状■
マークダウン
html
1[hoge](http://example.com){: target="_blank"}
htmlへ変換された内容
<a href="http://example.com">hoge</a> {: target="_blank"}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/21 12:40
2018/02/21 12:41