Created
October 16, 2013 20:21
-
-
Save anonymous/7014137 to your computer and use it in GitHub Desktop.
redcarpet2_markdown with pygments
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
require 'fileutils' | |
require 'digest/md5' | |
require 'redcarpet' | |
require 'pygments' | |
class Redcarpet2Markdown < Redcarpet::Render::HTML | |
def block_code(code, lang) | |
lang = lang || "text" | |
colorized = Pygments.highlight(code, :lexer => lang, :options => { :style => "default", :encoding => 'utf-8'}) | |
add_code_tags(colorized, lang) | |
end | |
def add_code_tags(code, lang) | |
code.sub(/<pre>/, "<pre><code class=\"#{lang}\">"). | |
sub(/<\/pre>/, "</code></pre>") | |
end | |
end | |
class Jekyll::MarkdownConverter | |
def extensions | |
Hash[ *@config['redcarpet']['extensions'].map {|e| [e.to_sym, true] }.flatten ] | |
end | |
def markdown | |
@markdown ||= Redcarpet::Markdown.new(Redcarpet2Markdown.new(extensions), extensions) | |
end | |
def convert(content) | |
return super unless @config['markdown'] == 'redcarpet2' | |
markdown.render(content) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment