Allow redcarpet to add nofollow to links
This, using a new feature in redcarpet, allows us to avoid having to subclass the renderer and implement links ourselves, which in turn means that redcarpet's link sanitisation works.
This commit is contained in:
parent
ce6d7966a1
commit
4e95ff1707
1 changed files with 1 additions and 15 deletions
|
@ -80,26 +80,12 @@ module RichText
|
|||
end
|
||||
|
||||
def self.html_renderer
|
||||
@html_renderer ||= Renderer.new(:filter_html => true, :safe_links_only => true)
|
||||
@html_renderer ||= Redcarpet::Render::XHTML.new(:filter_html => true, :safe_links_only => true, :link_attributes => { :rel => "nofollow" })
|
||||
end
|
||||
|
||||
def self.html_parser
|
||||
@html_parser ||= Redcarpet::Markdown.new(html_renderer, :no_intra_emphasis => true, :autolink => true, :space_after_headers => true)
|
||||
end
|
||||
|
||||
class Renderer < Redcarpet::Render::XHTML
|
||||
def link(link, _title, alt_text)
|
||||
"<a rel=\"nofollow\" href=\"#{link}\">#{alt_text}</a>"
|
||||
end
|
||||
|
||||
def autolink(link, link_type)
|
||||
if link_type == :email
|
||||
"<a rel=\"nofollow\" href=\"mailto:#{link}\">#{link}</a>"
|
||||
else
|
||||
"<a rel=\"nofollow\" href=\"#{link}\">#{link}</a>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Text < Base
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue