Created
June 12, 2012 16:26
-
-
Save r10r/2918523 to your computer and use it in GitHub Desktop.
Generating HTML markup from github flavored markdown including syntax highlighting
This file contains 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
@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