Created
April 10, 2013 19:44
-
-
Save jwo/5357811 to your computer and use it in GitHub Desktop.
Github flavored markdown on rails 4.0
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
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