Not sure if this is the rails way of doing things, but it seems fine, and doesn't violate POLA or the like, so hopefully it will suit your needs.
Create a markdown.rb
file in your config/initializers/
folder, and use some variation of the following code snippet:
class MultiRenderer < Redcarpet::Render::HTML
include Redcarpet::Render::SmartyPants
end
module Paradox
Markdown = Redcarpet::Markdown.new(MultiRenderer)
end
Replace Paradox
with the name of your application. You can add various options to the renderer or the instance of markdown, as described in the readme. The renderer I created (the MultiRenderer
) has built in smartypants, so you can round quotes and whatnot
To use Markdown, simply call YourApp::Markdown.render(text)
, and you'll get html back. You probably need to run html_safe on that.