Merge branch 'steal-envygeeks-custom-markdown-processors' of git://github.com/gjtorikian/jekyll into gjtorikian-steal-envygeeks-custom-markdown-processors
* 'steal-envygeeks-custom-markdown-processors' of git://github.com/gjtorikian/jekyll: Depend on Jekyll.logger.error, not $stderr Allow custom Markdown processors. New is implied by `raise`, 2nd is the message. Use $stderr, not STDERR, $stderr points to STDERR.
This commit is contained in:
commit
c70350e275
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue