Class: Moft::Converters::Markdown::KramdownParser

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ KramdownParser

Returns a new instance of KramdownParser.



5
6
7
8
9
10
11
12
# File 'lib/moft/converters/markdown/kramdown_parser.rb', line 5

def initialize(config)
  require 'kramdown'
  @config = config
rescue LoadError
  STDERR.puts 'You are missing a library required for Markdown. Please run:'
  STDERR.puts '  $ [sudo] gem install kramdown'
  raise FatalException.new("Missing dependency: kramdown")
end

Instance Method Details

#base_kramdown_configsObject



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

def base_kramdown_configs
  {
    :auto_ids      => @config['kramdown']['auto_ids'],
    :footnote_nr   => @config['kramdown']['footnote_nr'],
    :entity_output => @config['kramdown']['entity_output'],
    :toc_levels    => @config['kramdown']['toc_levels'],
    :smart_quotes  => @config['kramdown']['smart_quotes']
  }
end

#convert(content) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/moft/converters/markdown/kramdown_parser.rb', line 14

def convert(content)
  # Check for use of coderay
  kramdown_configs = if @config['kramdown']['use_coderay']
    base_kramdown_configs.merge({
      :coderay_wrap               => @config['kramdown']['coderay']['coderay_wrap'],
      :coderay_line_numbers       => @config['kramdown']['coderay']['coderay_line_numbers'],
      :coderay_line_number_start  => @config['kramdown']['coderay']['coderay_line_number_start'],
      :coderay_tab_width          => @config['kramdown']['coderay']['coderay_tab_width'],
      :coderay_bold_every         => @config['kramdown']['coderay']['coderay_bold_every'],
      :coderay_css                => @config['kramdown']['coderay']['coderay_css']
    })
  else
    # not using coderay
    base_kramdown_configs
  end
  Kramdown::Document.new(content, kramdown_configs).to_html
end