rescue block for the method and added redcarpet as option for parser

This commit is contained in:
Parker Moore 2013-04-13 02:13:50 +02:00
parent 3bc497c1c9
commit a971fec801
2 changed files with 21 additions and 23 deletions

View File

@ -19,7 +19,7 @@ module Jekyll
MarukuParser.new @config MarukuParser.new @config
else else
STDERR.puts "Invalid Markdown processor: #{@config['markdown']}" STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
STDERR.puts " Valid options are [ maruku | rdiscount | kramdown ]" STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
raise FatalException.new("Invalid Markdown process: #{@config['markdown']}") raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
end end
@setup = true @setup = true

View File

@ -3,31 +3,29 @@ module Jekyll
class Markdown class Markdown
class RedcarpetParser class RedcarpetParser
def initialize(config) def initialize(config)
begin require 'redcarpet'
require 'redcarpet' @config = config
@config = config @redcarpet_extensions = {}
@redcarpet_extensions = {} @config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
@config['redcarpet']['extensions'].each { |e| @redcarpet_extensions[e.to_sym] = true }
@renderer ||= Class.new(Redcarpet::Render::HTML) do @renderer ||= Class.new(Redcarpet::Render::HTML) do
def block_code(code, lang) def block_code(code, lang)
lang = lang && lang.split.first || "text" lang = lang && lang.split.first || "text"
output = add_code_tags( output = add_code_tags(
Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }), Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8' }),
lang lang
) )
end end
def add_code_tags(code, lang) def add_code_tags(code, lang)
code = code.sub(/<pre>/,'<pre><code class="' + lang + '">') code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
code = code.sub(/<\/pre>/,"</code></pre>") code = code.sub(/<\/pre>/,"</code></pre>")
end
end end
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install redcarpet'
raise FatalException.new("Missing dependency: redcarpet")
end end
rescue LoadError
STDERR.puts 'You are missing a library required for Markdown. Please run:'
STDERR.puts ' $ [sudo] gem install redcarpet'
raise FatalException.new("Missing dependency: redcarpet")
end end
def convert(content) def convert(content)