Class: GitHub::Markup::Markdown

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

Constant Summary collapse

MARKDOWN_GEMS =
{
  "commonmarker" => proc { |content, options: {}|
    commonmarker_opts = [:GITHUB_PRE_LANG].concat(options.fetch(:commonmarker_opts, []))
    commonmarker_exts = options.fetch(:commonmarker_exts, [:tagfilter, :autolink, :table, :strikethrough])
    CommonMarker.render_html(content, commonmarker_opts, commonmarker_exts)
  },
  "github/markdown" => proc { |content, options: {}|
    GitHub::Markdown.render(content)
  },
  "redcarpet" => proc { |content, options: {}|
    Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content)
  },
  "rdiscount" => proc { |content, options: {}|
    RDiscount.new(content).to_html
  },
  "maruku" => proc { |content, options: {}|
    Maruku.new(content).to_html
  },
  "kramdown" => proc { |content, options: {}|
    Kramdown::Document.new(content).to_html
  },
  "bluecloth" => proc { |content, options: {}|
    BlueCloth.new(content).to_html
  },
}

Instance Attribute Summary

Attributes inherited from Implementation

#languages, #regexp

Instance Method Summary collapse

Methods inherited from Implementation

#match?

Constructor Details

#initializeMarkdown

Returns a new instance of Markdown.



32
33
34
35
36
# File 'lib/github/markup/markdown.rb', line 32

def initialize
  super(
    /md|mkdn?|mdwn|mdown|markdown|mdx|litcoffee/i,
    ["Markdown", "MDX", "Literate CoffeeScript"])
end

Instance Method Details

#loadObject

Raises:

  • (LoadError)


38
39
40
41
42
43
44
45
46
47
# File 'lib/github/markup/markdown.rb', line 38

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

#nameObject



54
55
56
# File 'lib/github/markup/markdown.rb', line 54

def name
  "markdown"
end

#render(filename, content, options: {}) ⇒ Object



49
50
51
52
# File 'lib/github/markup/markdown.rb', line 49

def render(filename, content, options: {})
  load
  @renderer.call(content, options: options)
end