Created
September 23, 2013 07:47
-
-
Save lawitschka/6667570 to your computer and use it in GitHub Desktop.
Rendering sections of ERb templates in Markdown with Rails
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
<%= markdown do %> | |
# About | |
a paragraph.... | |
* one | |
* two | |
<% end %> |
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
module MarkdownHelper | |
class Markdown | |
class << self | |
def renderer | |
@@renderer ||= Redcarpet::Markdown.new( | |
Redcarpet::Render::HTML, | |
:autolink => true, | |
:no_intra_emphasis => true, | |
:tables => true, | |
:fenced_code_blocks => true, | |
:disable_indented_code_blocks => true, | |
:filter_html => false, | |
:with_toc_data => true | |
) | |
end | |
end | |
end | |
def markdown(&block) | |
content = capture(&block) | |
Markdown.renderer.render(content).html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment