Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created February 28, 2012 12:55
Show Gist options
  • Select an option

  • Save asmallteapot/1932387 to your computer and use it in GitHub Desktop.

Select an option

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.
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