Class: GitHub::Markup::Markdown

Inherits:
Implementation show all
Defined in:
lib/github/markup/markdown.rb

Constant Summary collapse

MARKDOWN_GEMS =
{
  "github/markdown" => proc { |content|
    GitHub::Markdown.render(content)
  },
  "redcarpet" => proc { |content|
    RedcarpetCompat.new(content).to_html
  },
  "rdiscount" => proc { |content|
    RDiscount.new(content).to_html
  },
  "maruku" => proc { |content|
    Maruku.new(content).to_html
  },
  "kramdown" => proc { |content|
    Kramdown::Document.new(content).to_html
  },
  "bluecloth" => proc { |content|
    BlueCloth.new(content).to_html
  },
}

Instance Attribute Summary

Attributes inherited from Implementation

#regexp

Instance Method Summary collapse

Methods inherited from Implementation

#match?

Constructor Details

#initializeMarkdown

Returns a new instance of Markdown.



27
28
29
# File 'lib/github/markup/markdown.rb', line 27

def initialize
  super(/md|mkdn?|mdwn|mdown|markdown|litcoffee/)
end

Instance Method Details

#loadObject

Raises:

  • (LoadError)


31
32
33
34
35
36
37
38
39
40
# File 'lib/github/markup/markdown.rb', line 31

def load
  return if @renderer
  MARKDOWN_GEMS.each do |gem_name, renderer|
    if try_require(gem_name)
      @renderer = renderer
      return
    end
  end
  raise LoadError, "no suitable markdown gem found"
end

#render(content) ⇒ Object



42
43
44
45
# File 'lib/github/markup/markdown.rb', line 42

def render(content)
  load
  @renderer.call(content)
end