Skip to content

Instantly share code, notes, and snippets.

@stephencelis
Created August 29, 2011 05:54
Show Gist options
  • Save stephencelis/1177847 to your computer and use it in GitHub Desktop.
Save stephencelis/1177847 to your computer and use it in GitHub Desktop.
Redcarpet (Markdown) template handler for Rails 3.1.
# config/initializers/redcarpet.rb
class ActionView::Template
class Redcarpet < Handler
include Handlers::Compilable
def compile template
::Redcarpet.new(template.source).to_html.inspect
end
end
register_template_handler :markdown, Redcarpet
end
@dgmstuart
Copy link

This mostly worked for me (Awesome!) but the generated html ended up being escaped. I used the following (copied from the markdown-rails gem) instead:

 markdown.render(template.source).inspect + '.html_safe'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment