Class: Jekyll::Converters::Markdown::KramdownParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/converters/markdown/kramdown_parser.rb

Constant Summary

CODERAY_DEFAULTS =
{
  "css"               => "style",
  "bold_every"        => 10,
  "line_numbers"      => "inline",
  "line_number_start" => 1,
  "tab_width"         => 4,
  "wrap"              => "div",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ KramdownParser

Returns a new instance of KramdownParser



16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/converters/markdown/kramdown_parser.rb', line 16

def initialize(config)
  unless defined?(Kramdown)
    Jekyll::External.require_with_graceful_fail "kramdown"
  end
  @main_fallback_highlighter = config["highlighter"] || "rouge"
  @config = config["kramdown"] || {}
  @highlighter = nil
  setup
end

Instance Method Details

#convert(content) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/converters/markdown/kramdown_parser.rb', line 41

def convert(content)
  document = Kramdown::Document.new(content, @config)
  html_output = document.to_html
  if @config["show_warnings"]
    document.warnings.each do |warning|
      Jekyll.logger.warn "Kramdown warning:", warning
    end
  end
  html_output
end

#setupObject

Setup and normalize the configuration:

* Create Kramdown if it doesn't exist.
* Set syntax_highlighter, detecting enable_coderay and merging
    highlighter if none.
* Merge kramdown[coderay] into syntax_highlighter_opts stripping coderay_.
* Make sure `syntax_highlighter_opts` exists.


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

def setup
  @config["syntax_highlighter"] ||= highlighter
  @config["syntax_highlighter_opts"] ||= {}
  @config["coderay"] ||= {} # XXX: Legacy.
  modernize_coderay_config
  make_accessible
end