docbrown/app/lib/redcarpet/render/html_rouge.rb
Yechiel Kalmenson 37e0059ade open markdown links in new tab (take 2) (#512)
* open links in chats in new tabs

* fixed target_blank vulnerability

* add test to make sur links are being generated with target _blank

* add test for target blank vulnerability

* add rel and target to the whitelisted attributes

* add the link attributes to HTMLRouge#link
2018-07-11 15:04:03 -04:00

20 lines
573 B
Ruby

require "rouge/plugins/redcarpet"
module Redcarpet
module Render
class HTMLRouge < HTML
include Rouge::Plugins::Redcarpet
def link(link, _title, content)
# Probably not the best fix but it does it's job of preventing
# a nested links.
return nil if /<a\s.+\/a>/.match?(content)
link_attributes = ""
@options[:link_attributes]&.each do |attribute, value|
link_attributes += %( #{attribute}="#{value}")
end
%(<a href="#{link}"#{link_attributes}>#{content}</a>)
end
end
end
end