Skip to content

Instantly share code, notes, and snippets.

@nacengineer
Created April 29, 2012 20:36
Show Gist options
  • Save nacengineer/2553125 to your computer and use it in GitHub Desktop.
Save nacengineer/2553125 to your computer and use it in GitHub Desktop.
Railscast #272 with Redcarpet 2.0 helper code
def markdown(text)
options = {hard_wrap: true, filter_html: true, autolink: true, no_intraemphasis: true, fenced_code: true, gh_blockcode: true}
md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, extensions = options)
syntax_highlighter( md.render(text) ).html_safe
end
def syntax_highlighter(html)
doc = Nokogiri::HTML(html)
doc.search("//pre[@lang]").each do |pre|
pre.replace Albino.colorize(pre.text.rstrip, pre[:lang])
end
doc.to_s
end
@nacengineer
Copy link
Author

See comment by Braulio Carreno at end of comments for a better way of doing this with pygments.rb gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment