Skip to content

Instantly share code, notes, and snippets.

@r10r
Created June 12, 2012 16:26
Show Gist options
  • Save r10r/2918523 to your computer and use it in GitHub Desktop.
Save r10r/2918523 to your computer and use it in GitHub Desktop.
Generating HTML markup from github flavored markdown including syntax highlighting
@md_renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:autolink => true,
:space_after_headers => true,
:fenced_code_blocks => true)
def markdown(text)
syntax_highlighter(@md_renderer.render(text)).html_safe
end
def syntax_highlighter(html)
doc = Nokogiri::HTML(html)
doc.search("//code[@class]").each do |code|
code.replace Albino.colorize(code.text.rstrip, code[:class])
# or use coderay
#code.replace CodeRay.scan(code.text.rstrip, code[:class]).html(:line_numbers => :table)
end
doc.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment