From: Tom Hughes Date: Fri, 16 Mar 2012 22:38:04 +0000 (+0000) Subject: Add rel="nofollow" to links generated from Markdown X-Git-Tag: live~6278 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/584806af9239154f3af22da3e66a054c2d8e147f Add rel="nofollow" to links generated from Markdown --- diff --git a/lib/rich_text.rb b/lib/rich_text.rb index 9c4a24fd5..92be8903b 100644 --- a/lib/rich_text.rb +++ b/lib/rich_text.rb @@ -71,13 +71,27 @@ module RichText private def html_parser - @@html_renderer ||= Redcarpet::Render::XHTML.new({ + @@html_renderer ||= Renderer.new({ :filter_html => true, :safe_links_only => true }) @@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) + "#{alt_text}" + end + + def autolink(link, link_type) + if link_type == :email + "#{link}" + else + "#{link}" + end + end + end end class Text < Base