Browse files

Made it possible to pass settings to the renderer.

  • Loading branch information...
1 parent e112976 commit ae694932ffef1255287c5cb360910c1176deb78c @njakobsen njakobsen committed Dec 3, 2011
Showing with 11 additions and 5 deletions.
  1. +9 −3 app/helpers/editable_contents_helper.rb
  2. +2 −2 app/models/editable_content.rb
View
12 app/helpers/editable_contents_helper.rb
@@ -1,6 +1,12 @@
module EditableContentsHelper
- def markdown(string)
- @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, :tables => true, :autolink => true, :space_after_headers => true)
- @markdown.render(string).html_safe
+ def markdown(string, options = nil)
+ options ||= {:tables => true, :autolink => true, :space_after_headers => true, :hard_wrap => true}
+ @markdown_renderers ||= {}
+
+ unless renderer = @markdown_renderers[options]
+ renderer = @markdown_renderers[options] = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(options), options)
+ end
+
+ renderer.render(string).html_safe
end
end
View
4 app/models/editable_content.rb
@@ -21,8 +21,8 @@ def to_s
self.body
end
- def to_html
- markdown(self.body)
+ def to_html(options = nil)
+ markdown(self.body, options)
end
private

0 comments on commit ae69493

Please sign in to comment.