Skip to content

Instantly share code, notes, and snippets.

@clowder
Created December 14, 2016 21:16
Show Gist options
  • Save clowder/38b0c0449a90fcfa4a305a7b3a0af5d8 to your computer and use it in GitHub Desktop.
Save clowder/38b0c0449a90fcfa4a305a7b3a0af5d8 to your computer and use it in GitHub Desktop.
A markdown ActionView::Template hander for Rails, that supports string interpolation
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
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