Skip to content

Instantly share code, notes, and snippets.

@mattlenz
Created July 27, 2012 01:03
Show Gist options
  • Save mattlenz/3185536 to your computer and use it in GitHub Desktop.
Save mattlenz/3185536 to your computer and use it in GitHub Desktop.
Rails Markdown (Kramdown) Template Handler
# config/initializers/markdown_handler.rb
module MarkdownHandler
def self.erb
@erb ||= ActionView::Template.registered_template_handler(:erb)
end
def self.call(template)
compiled_source = erb.call(template)
"Kramdown::Document.new(begin;#{compiled_source};end, auto_ids: false).to_html"
end
end
ActionView::Template.register_template_handler :md, MarkdownHandler
ActionView::Template.register_template_handler :markdown, MarkdownHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment