Created
February 28, 2012 12:55
-
-
Save asmallteapot/1932387 to your computer and use it in GitHub Desktop.
Markdown + syntax highlighting. Can’t remember where I stole this from. Probably one of the GitHub folk.
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
| gem 'redcarpet' | |
| gem 'albino' # requires pgyments | |
| gem 'nokogiri' | |
| def markdown(text) | |
| options = [ | |
| :autolink, :fenced_code, :filter_html, :gh_blockcode, :hard_wrap | |
| :no_intraemphasis, :strikethrough, :tables, :xhtml | |
| ] | |
| syntax_highlighter(Redcarpet.new(text, *options).to_html.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