diff --git a/lib/jekyll/converters/markdown.rb b/lib/jekyll/converters/markdown.rb index 485cac82..9727f5a4 100644 --- a/lib/jekyll/converters/markdown.rb +++ b/lib/jekyll/converters/markdown.rb @@ -8,20 +8,22 @@ module Jekyll def setup return if @setup - @parser = case @config['markdown'] - when 'redcarpet' - RedcarpetParser.new @config - when 'kramdown' - KramdownParser.new @config - when 'rdiscount' - RDiscountParser.new @config - when 'maruku' - MarukuParser.new @config + @parser = + case @config['markdown'] + when 'redcarpet' then RedcarpetParser.new(@config) + when 'kramdown' then KramdownParser.new(@config) + when 'rdiscount' then RDiscountParser.new(@config) + when 'maruku' then MarukuParser.new(@config) else - STDERR.puts "Invalid Markdown processor: #{@config['markdown']}" - STDERR.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]" - raise FatalException.new("Invalid Markdown process: #{@config['markdown']}") - end + # So they can't try some tricky bullshit or go down the ancestor chain, I hope. + if @config['markdown'] !~ /[^A-Za-z0-9]/ && self.class.constants.include?(@config['markdown'].to_sym) + self.class.const_get(@config['markdown']).new(@config) + else + Jekyll.logger.error "Invalid Markdown Processor:", "#{@config['markdown']}" + Jekyll.logger.error "", "Valid options are [ maruku | rdiscount | kramdown | redcarpet ]" + raise FatalException, "Invalid Markdown process: #{@config['markdown']}" + end + end @setup = true end diff --git a/test/test_site.rb b/test/test_site.rb index a530f9d0..04e2b3d0 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -262,6 +262,52 @@ class TestSite < Test::Unit::TestCase 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 should 'not throw an error at initialization time' do bad_processor = 'not a processor name'