Created
April 29, 2012 20:36
-
-
Save nacengineer/2553125 to your computer and use it in GitHub Desktop.
Railscast #272 with Redcarpet 2.0 helper code
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See comment by Braulio Carreno at end of comments for a better way of doing this with pygments.rb gem.