Last active
December 22, 2015 14:59
-
-
Save albertogg/6489456 to your computer and use it in GitHub Desktop.
Rails markdown template handler with redcarpet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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