public
Last active

Redcarpet (Markdown) template handler for Rails 3.1.

  • Download Gist
redcarpet.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
# 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

Slick. Is there a way to wire the markdown file up so you can do ERB-like stuff (like iterating over objects), etc.?

As long as you name the template {template_name}.html.markdown.erb, it should let you embed ERB tags into the Markdown document.

FYI, I changed my template name as {template_name}.html.markdown.erb, but didn't work. "No such page" error occurred.

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'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.