Skip to content

Instantly share code, notes, and snippets.

@r38y
Created March 2, 2013 16:57
Show Gist options
  • Save r38y/5071958 to your computer and use it in GitHub Desktop.
Save r38y/5071958 to your computer and use it in GitHub Desktop.
Rendering Markdown
module ApplicationHelper
def md(text)
text = text || ''
# in very clear cases, let newlines become <br /> tags
text.gsub!(/^[\w\"\<][^\n]*\n+/) do |x|
x =~ /\n{2}/ ? x : (x.strip!; x << " \n")
end
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, space_after_headers: true)
markdown.render(text).html_safe
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment