Skip to content

Instantly share code, notes, and snippets.

@t7y
Forked from stephencelis/redcarpet.rb
Created June 10, 2013 17:25
Show Gist options
  • Save t7y/5750616 to your computer and use it in GitHub Desktop.
Save t7y/5750616 to your computer and use it in GitHub Desktop.
# 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
@t7y
Copy link
Author

t7y commented Jun 10, 2013

Updated for rails 3.2.x

module MarkdownTemplateHandler
  def self.call(template)
    "Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true).render(#{template.source.inspect}).html_safe"
  end
end
ActionView::Template.register_template_handler(:md, MarkdownTemplateHandler)

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