Module: Ichiban::Markdown

Defined in:
lib/ichiban/markdown.rb

Class Method Summary collapse

Class Method Details

.compile(src) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ichiban/markdown.rb', line 3

def self.compile(src)
  require_markdown
  case @strategy
  when :kramdown
    Kramdown::Document.new(src).to_html
  when :multimarkdown
    MultiMarkdown.new(src).to_html
  when :redcarpet
    @redcarpet.render(src)
  when :maruku
    Maruku.new(src).to_html
  when :rdiscount
    RDiscount.new(src).to_html
  else
    raise "unrecognized @strategy: #{@strategy}"
  end
end

.require_markdownObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ichiban/markdown.rb', line 21

def self.require_markdown
  unless @markdown_loaded
    case Ichiban.try_require('kramdown', 'multimarkdown', 'redcarpet', 'maruku', 'rdiscount')
    when 'kramdown'
      @strategy = :kramdown
    when 'multimarkdown'
      @strategy = :multimarkdown
    when 'redcarpet'
      @redcarpet = Redcarpet::Markdown.new(Redcarpet::Render::XHTML.new)
      @strategy = :redcarpet
    when 'maruku'
      @strategy = :maruku
    when 'rdiscount'
      @strategy = :rdiscount
    else
      raise("Your Ichiban project contains at least one Markdown file. To process it, " +
            "you need to gem install one of: rpeg-multimarkdown redcarpet maruku rdiscount.")
    end
    @markdown_loaded = true
  end
end