Allow custom Markdown processors.

This commit is contained in:
Jordon 2013-06-15 06:00:47 -05:00 committed by Garen Torikian
parent 626d54a812
commit c759a7a75f
2 changed files with 61 additions and 13 deletions

View File

@ -8,20 +8,22 @@ module Jekyll
def setup def setup
return if @setup return if @setup
@parser = case @config['markdown'] @parser =
when 'redcarpet' case @config['markdown']
RedcarpetParser.new @config when 'redcarpet' then RedcarpetParser.new(@config)
when 'kramdown' when 'kramdown' then KramdownParser.new(@config)
KramdownParser.new @config when 'rdiscount' then RDiscountParser.new(@config)
when 'rdiscount' when 'maruku' then MarukuParser.new(@config)
RDiscountParser.new @config else
when 'maruku' # So they can't try some tricky bullshit or go down the ancestor chain, I hope.
MarukuParser.new @config if @config['markdown'] !~ /[^A-Za-z0-9]/ && self.class.constants.include?(@config['markdown'].to_sym)
self.class.const_get(@config['markdown']).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 | redcarpet ]" $stderr.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
raise FatalException, "Invalid Markdown process: #{@config['markdown']}" raise FatalException, "Invalid Markdown process: #{@config['markdown']}"
end end
end
@setup = true @setup = true
end end

View File

@ -255,6 +255,52 @@ class TestSite < Test::Unit::TestCase
end end
end end
context 'using a non-default markdown processor in the configuration' do
should 'use the non-default markdown processor' do
class Jekyll::Converters::Markdown::CustomMarkdown
def initialize(*args)
@args = args
end
def convert(*args)
""
end
end
custom_processor = "CustomMarkdown"
s = Site.new(Jekyll.configuration.merge({ 'markdown' => custom_processor }))
assert_nothing_raised do
s.process
end
# Do some cleanup, we don't like straggling stuff's.
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
end
should 'ignore, if there are any bad characters in the class name' do
module Jekyll::Converters::Markdown::Custom
class Markdown
def initialize(*args)
@args = args
end
def convert(*args)
""
end
end
end
bad_processor = "Custom::Markdown"
s = Site.new(Jekyll.configuration.merge({ 'markdown' => bad_processor }))
assert_raise Jekyll::FatalException do
s.process
end
# Do some cleanup, we don't like straggling stuff's.
Jekyll::Converters::Markdown.send(:remove_const, :Custom)
end
end
context 'with an invalid markdown processor in the configuration' do context 'with an invalid markdown processor in the configuration' do
should 'not throw an error at initialization time' do should 'not throw an error at initialization time' do
bad_processor = 'not a processor name' bad_processor = 'not a processor name'