Allow custom Markdown processors.
This commit is contained in:
parent
626d54a812
commit
c759a7a75f
|
@ -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
|
||||
# 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
|
||||
$stderr.puts "Invalid Markdown processor: #{@config['markdown']}"
|
||||
$stderr.puts " Valid options are [ maruku | rdiscount | kramdown | redcarpet ]"
|
||||
raise FatalException, "Invalid Markdown process: #{@config['markdown']}"
|
||||
end
|
||||
end
|
||||
@setup = true
|
||||
end
|
||||
|
||||
|
|
|
@ -255,6 +255,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