lib/bunto/converters/markdown.rb in bunto-3.0.0 vs lib/bunto/converters/markdown.rb in bunto-3.2.1

- old
+ new

@@ -7,27 +7,37 @@ def setup return if @setup ||= false unless (@parser = get_processor) Bunto.logger.error "Invalid Markdown processor given:", @config["markdown"] - Bunto.logger.info "", "Custom processors are not loaded in safe mode" if @config["safe"] - Bunto.logger.error "", "Available processors are: #{valid_processors.join(", ")}" + if @config["safe"] + Bunto.logger.info "", "Custom processors are not loaded in safe mode" + end + Bunto.logger.error( + "", + "Available processors are: #{valid_processors.join(", ")}" + ) raise Errors::FatalException, "Bailing out; invalid Markdown processor." end @setup = true end + # 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 Style/AccessorMethodName def get_processor case @config["markdown"].downcase when "redcarpet" then return RedcarpetParser.new(@config) when "kramdown" then return KramdownParser.new(@config) when "rdiscount" then return RDiscountParser.new(@config) else - get_custom_processor + custom_processor end end + # rubocop:enable Style/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.) @@ -39,17 +49,17 @@ # 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. def third_party_processors self.class.constants - \ - %w(KramdownParser RDiscountParser RedcarpetParser PRIORITIES).map( - &:to_sym - ) + %w(KramdownParser RDiscountParser RedcarpetParser PRIORITIES).map( + &:to_sym + ) end def extname_list - @extname_list ||= @config['markdown_ext'].split(',').map do |e| + @extname_list ||= @config["markdown_ext"].split(",").map do |e| ".#{e.downcase}" end end def matches(ext) @@ -64,11 +74,11 @@ setup @parser.convert(content) end private - def get_custom_processor + def custom_processor converter_name = @config["markdown"] if custom_class_allowed?(converter_name) self.class.const_get(converter_name).new(@config) end end @@ -81,10 +91,10 @@ # Returns true if the parser name contains only alphanumeric # characters and is defined within Bunto::Converters::Markdown private def custom_class_allowed?(parser_name) - parser_name !~ /[^A-Za-z0-9_]/ && self.class.constants.include?( + parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?( parser_name.to_sym ) end end end