class Jekyll::Converters::Markdown

Public Instance Methods

convert(content) click to toggle source
# File lib/jekyll/converters/markdown.rb, line 64
def convert(content)
  setup
  @parser.convert(content)
end
extname_matches_regexp() click to toggle source
# File lib/jekyll/converters/markdown.rb, line 49
def extname_matches_regexp
  @extname_matches_regexp ||= Regexp.new(
    '^\.(' + @config['markdown_ext'].gsub(',','|') +')$',
    Regexp::IGNORECASE
  )
end
matches(ext) click to toggle source
# File lib/jekyll/converters/markdown.rb, line 56
def matches(ext)
  ext =~ extname_matches_regexp
end
output_ext(ext) click to toggle source
# File lib/jekyll/converters/markdown.rb, line 60
def output_ext(ext)
  ".html"
end
setup() click to toggle source
# File lib/jekyll/converters/markdown.rb, line 9
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 [ #{valid_processors.join(" | ")} ]"
        raise Errors::FatalException, "Invalid Markdown Processor: #{@config['markdown']}"
      end
    end
  @setup = true
end
third_party_processors() click to toggle source
# File lib/jekyll/converters/markdown.rb, line 39
def third_party_processors
  self.class.constants - %w[
    KramdownParser
    MarukuParser
    RDiscountParser
    RedcarpetParser
    PRIORITIES
  ].map(&:to_sym)
end
valid_processors() click to toggle source
# File lib/jekyll/converters/markdown.rb, line 30
def valid_processors
  %w[
    maruku
    rdiscount
    kramdown
    redcarpet
  ] + third_party_processors
end

Private Instance Methods

allowed_custom_class?(parser_name) click to toggle source

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

# File lib/jekyll/converters/markdown.rb, line 78
def allowed_custom_class?(parser_name)
  parser_name !~ /[^A-Za-z0-9]/ && self.class.constants.include?(parser_name.to_sym)
end