Skip to content

Instantly share code, notes, and snippets.

@jwo
Created April 10, 2013 19:44
Show Gist options
  • Save jwo/5357811 to your computer and use it in GitHub Desktop.
Save jwo/5357811 to your computer and use it in GitHub Desktop.
Github flavored markdown on rails 4.0
require 'html/pipeline'
module MarkdownHandler
def self.call(template)
erb = ActionView::Template.registered_template_handler(:erb)
source = erb.call(template)
<<-SOURCE
pipeline = HTML::Pipeline.new [
HTML::Pipeline::MarkdownFilter,
HTML::Pipeline::SyntaxHighlightFilter
]
result = pipeline.call(begin;#{source};end)
result[:output].to_s
SOURCE
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