Class: Jekyll::Converters::Markdown

Inherits:
Jekyll::Converter show all
Defined in:
lib/ngage/jekyll/converters/markdown.rb,
lib/ngage/jekyll/converters/markdown/kramdown_parser.rb

Overview

Markdown converter. For more info on converters see jekyllrb.com/docs/plugins/converters/

Defined Under Namespace

Classes: KramdownParser

Constant Summary

Constants inherited from Plugin

Plugin::PRIORITIES

Instance Method Summary collapse

Methods inherited from Jekyll::Converter

highlighter_prefix, #highlighter_prefix, highlighter_suffix, #highlighter_suffix, #initialize

Methods inherited from Plugin

#<=>, <=>, catch_inheritance, descendants, inherited, #initialize, priority, safe

Constructor Details

This class inherits a constructor from Jekyll::Converter

Instance Method Details

#convert(content) ⇒ Object

Logic to do the content conversion.

content - String content of file (without front matter).

Returns a String of the converted content.


90
91
92
93
# File 'lib/ngage/jekyll/converters/markdown.rb', line 90

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

#extname_listObject


60
61
62
63
64
# File 'lib/ngage/jekyll/converters/markdown.rb', line 60

def extname_list
  @extname_list ||= @config["markdown_ext"].split(",").map do |e|
    ".#{e.downcase}"
  end
end

#get_processorObject

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


32
33
34
35
36
37
38
# File 'lib/ngage/jekyll/converters/markdown.rb', line 32

def get_processor
  case @config["markdown"].downcase
  when "kramdown" then KramdownParser.new(@config)
  else
    custom_processor
  end
end

#matches(ext) ⇒ Object

Does the given extension match this converter’s list of acceptable extensions? Takes one argument: the file’s extension (including the dot).

ext - The String extension to check.

Returns true if it matches, false otherwise.


72
73
74
# File 'lib/ngage/jekyll/converters/markdown.rb', line 72

def matches(ext)
  extname_list.include?(ext.downcase)
end

#output_ext(_ext) ⇒ Object

Public: The extension to be given to the output file (including the dot).

ext - The String extension or original file.

Returns The String output file extension.


81
82
83
# File 'lib/ngage/jekyll/converters/markdown.rb', line 81

def output_ext(_ext)
  ".html"
end

#setupObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ngage/jekyll/converters/markdown.rb', line 12

def setup
  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."
  end

  @setup = true
end

#third_party_processorsObject

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.


53
54
55
56
57
58
# File 'lib/ngage/jekyll/converters/markdown.rb', line 53

def third_party_processors
  self.class.constants - \
    %w(KramdownParser PRIORITIES).map(
      &:to_sym
    )
end

#valid_processorsObject

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.)


45
46
47
# File 'lib/ngage/jekyll/converters/markdown.rb', line 45

def valid_processors
  %w(kramdown) + third_party_processors
end