Skip to content

Instantly share code, notes, and snippets.

@roachhd
Created November 6, 2014 06:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roachhd/124a9bfe2724fdca9203 to your computer and use it in GitHub Desktop.
Save roachhd/124a9bfe2724fdca9203 to your computer and use it in GitHub Desktop.
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