Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redcarpet (Markdown) template handler for Rails 3.1.
# config/initializers/redcarpet.rb
class ActionView::Template
class Redcarpet < Handler
include Handlers::Compilable
def compile template
::Redcarpet.new(template.source).to_html.inspect
end
end
register_template_handler :markdown, Redcarpet
end
@avand

This comment has been minimized.

Show comment
Hide comment
@avand

avand Sep 20, 2011

Slick. Is there a way to wire the markdown file up so you can do ERB-like stuff (like iterating over objects), etc.?

avand commented Sep 20, 2011

Slick. Is there a way to wire the markdown file up so you can do ERB-like stuff (like iterating over objects), etc.?

@stephencelis

This comment has been minimized.

Show comment
Hide comment
@stephencelis

stephencelis Sep 20, 2011

As long as you name the template {template_name}.html.markdown.erb, it should let you embed ERB tags into the Markdown document.

Owner

stephencelis commented Sep 20, 2011

As long as you name the template {template_name}.html.markdown.erb, it should let you embed ERB tags into the Markdown document.

@sjoonk

This comment has been minimized.

Show comment
Hide comment
@sjoonk

sjoonk Sep 26, 2011

FYI, I changed my template name as {template_name}.html.markdown.erb, but didn't work. "No such page" error occurred.

sjoonk commented Sep 26, 2011

FYI, I changed my template name as {template_name}.html.markdown.erb, but didn't work. "No such page" error occurred.

@dgmstuart

This comment has been minimized.

Show comment
Hide comment
@dgmstuart

dgmstuart Oct 13, 2012

This mostly worked for me (Awesome!) but the generated html ended up being escaped. I used the following (copied from the markdown-rails gem) instead:

 markdown.render(template.source).inspect + '.html_safe'

dgmstuart commented Oct 13, 2012

This mostly worked for me (Awesome!) but the generated html ended up being escaped. I used the following (copied from the markdown-rails gem) instead:

 markdown.render(template.source).inspect + '.html_safe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment