]> git.openstreetmap.org Git - rails.git/commitdiff
Add rel="nofollow" to links generated from Markdown
authorTom Hughes <tom@compton.nu>
Fri, 16 Mar 2012 22:38:04 +0000 (22:38 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 17 Mar 2012 16:37:19 +0000 (16:37 +0000)
lib/rich_text.rb

index 9c4a24fd54a11c18e7d50d3b65e8b137e768dc24..92be8903b03028d44483f24ba31fa5d96d331710 100644 (file)
@@ -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)
+        "<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