Sha256: 11a63d2ced0961daa647df7bdda5a3d42603b9a1fe701b838e6287269fe11121

Contents?: true

Size: 1.81 KB

Versions: 10

Compression:

Stored size: 1.81 KB

Contents

module Jekyll
  module Converters
    class Markdown < Converter
      safe true

      highlighter_prefix "\n"
      highlighter_suffix "\n"

      def setup
        return if @setup
        @parser =
          case @config['markdown'].downcase
            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 allowed_custom_class?(@config['markdown'])
              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 Processor: #{@config['markdown']}"
            end
          end
        @setup = true
      end

      def matches(ext)
        rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
        ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
      end

      def output_ext(ext)
        ".html"
      end

      def convert(content)
        setup
        @parser.convert(content)
      end

      private

      # Private: Determine whether a class name is an allowed custom markdown
      # class name
      #
      # 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
      def allowed_custom_class?(parser_name)
        parser_name !~ /[^A-Za-z0-9]/ && self.class.constants.include?(parser_name.to_sym)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
jekyll-2.1.1 lib/jekyll/converters/markdown.rb
jekyll-2.1.0 lib/jekyll/converters/markdown.rb
jekyll-2.0.3 lib/jekyll/converters/markdown.rb
jekyll-2.0.2 lib/jekyll/converters/markdown.rb
jekyll-2.0.1 lib/jekyll/converters/markdown.rb
jekyll-2.0.0 lib/jekyll/converters/markdown.rb
jekyll-2.0.0.rc1 lib/jekyll/converters/markdown.rb
jekyll-2.0.0.alpha.3 lib/jekyll/converters/markdown.rb
jekyll-2.0.0.alpha.2 lib/jekyll/converters/markdown.rb
jekyll-2.0.0.alpha.1 lib/jekyll/converters/markdown.rb