Cleanup Markdown converter (#7519)

Merge pull request 7519
This commit is contained in:
Ashwin Maroli 2019-03-15 23:00:39 +05:30 committed by jekyllbot
parent 7f2412c145
commit 18f7a28168
1 changed files with 25 additions and 32 deletions

View File

@ -13,21 +13,22 @@ module Jekyll
return if @setup ||= false
unless (@parser = get_processor)
Jekyll.logger.error "Invalid Markdown processor given:", @config["markdown"]
Jekyll.logger.info "", "Custom processors are not loaded in safe mode" if @config["safe"]
Jekyll.logger.error(
"",
"Available processors are: #{valid_processors.join(", ")}"
)
raise Errors::FatalException, "Bailing out; invalid Markdown processor."
if @config["safe"]
Jekyll.logger.warn "Build Warning:", "Custom processors are not loaded in safe mode"
end
Jekyll.logger.error "Markdown processor:",
"#{@config["markdown"].inspect} is not a valid Markdown processor."
Jekyll.logger.error "", "Available processors are: #{valid_processors.join(", ")}"
Jekyll.logger.error ""
raise Errors::FatalException, "Invalid Markdown processor given: #{@config["markdown"]}"
end
@cache = Jekyll::Cache.new("Jekyll::Converters::Markdown")
@setup = true
end
# Rubocop does not allow reader methods to have names starting with `get_`
# RuboCop does not allow reader methods to have names starting with `get_`
# To ensure compatibility, this check has been disabled on this method
#
# rubocop:disable Naming/AccessorMethodName
@ -40,29 +41,19 @@ module Jekyll
end
# rubocop:enable Naming/AccessorMethodName
# Public: Provides you with a list of processors, the ones we
# support internally and the ones that you have provided to us (if you
# are not in safe mode.)
# Public: Provides you with a list of processors comprised of the ones we support internally
# and the ones that you have provided to us (if they're whitelisted for use in safe mode).
#
# Returns an array of symbols.
def valid_processors
%w(kramdown) + third_party_processors
[:kramdown] + third_party_processors
end
# Public: A list of processors that you provide via plugins.
# This is really only available if you are not in safe mode, if you are
# in safe mode (re: GitHub) then there will be none.
#
# Returns an array of symbols
def third_party_processors
self.class.constants - \
%w(KramdownParser PRIORITIES).map(
&:to_sym
)
end
def extname_list
@extname_list ||= @config["markdown_ext"].split(",").map do |e|
".#{e.downcase}"
end
self.class.constants - [:KramdownParser, :PRIORITIES]
end
# Does the given extension match this converter's list of acceptable extensions?
@ -96,6 +87,10 @@ module Jekyll
end
end
def extname_list
@extname_list ||= @config["markdown_ext"].split(",").map! { |e| ".#{e.downcase}" }
end
private
def custom_processor
@ -108,12 +103,10 @@ module Jekyll
#
# parser_name - the name of the parser class
#
# Returns true if the parser name contains only alphanumeric
# characters and is defined within Jekyll::Converters::Markdown
# Returns true if the parser name contains only alphanumeric characters and is defined
# within Jekyll::Converters::Markdown
def custom_class_allowed?(parser_name)
parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?(
parser_name.to_sym
)
parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?(parser_name.to_sym)
end
end
end