]> git.openstreetmap.org Git - rails.git/blobdiff - lib/rich_text.rb
Don't preload the nodes as it seems to break the ordering
[rails.git] / lib / rich_text.rb
index 7d8010af1785ea6c9b275baf3fb572f997192ad2..533c8fbb4617b8af0540664d685433f9b2341ae5 100644 (file)
@@ -10,6 +10,7 @@ module RichText
 
   class SimpleFormat
     include ActionView::Helpers::TextHelper
+    include ActionView::Helpers::OutputSafetyHelper
 
     def sanitize(text)
       Sanitize.clean(text, Sanitize::Config::OSM).html_safe
@@ -82,13 +83,27 @@ module RichText
   private
 
     def html_parser
-      @@html_renderer ||= Redcarpet::Render::XHTML.new({
-        :filter_html => true, :safe_links_only => true, :link_attributes => { :rel => "nofollow" }
+      @@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