Skip to content

Instantly share code, notes, and snippets.

@albertogg
Last active December 22, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertogg/6489456 to your computer and use it in GitHub Desktop.
Save albertogg/6489456 to your computer and use it in GitHub Desktop.
Rails markdown template handler with redcarpet.
# config/initializers/redcarpet.rb
module ActionView
class Template
module Handlers
class Markdown
class_attribute :default_format
self.default_format = Mime::HTML
def call(template)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:autolink => true,
:space_after_headers => true,
:fenced_code_blocks => true)
markdown.render(template.source).html_safe.inspect
end
end
end
register_template_handler(:md, ActionView::Template::Handlers::Markdown.new)
register_template_handler(:mdown, ActionView::Template::Handlers::Markdown.new)
register_template_handler(:markdown, ActionView::Template::Handlers::Markdown.new)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment