Created
December 14, 2016 21:16
-
-
Save clowder/38b0c0449a90fcfa4a305a7b3a0af5d8 to your computer and use it in GitHub Desktop.
A markdown ActionView::Template hander for Rails, that supports string interpolation
This file contains hidden or 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 'redcarpet' | |
module Handlers | |
module Markdown | |
class HTMLWithPants < Redcarpet::Render::HTML | |
include Redcarpet::Render::SmartyPants | |
end | |
def self.call(template) | |
escaped_source = template.source.gsub('"', '\"') | |
"Redcarpet::Markdown.new(::Handlers::Markdown::HTMLWithPants, autolink: true, space_after_headers: true).render(\"#{ escaped_source }\")" | |
end | |
end | |
end | |
This file contains hidden or 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 './lib/handlers/markdown' | |
ActionView::Template.register_template_handler :md, Handlers::Markdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment