class Markdown::Parse

Constants

HTML

Public Class Methods

new(parser, theme = '') click to toggle source

parser - markdown processor

- kramdown
- redcarpet
- maruku
- rdiscount
# File lib/markdown_render/parse.rb, line 9
def initialize(parser, theme = '')
  @parser = parser
  @theme = theme
end

Public Instance Methods

to_document(content) click to toggle source
# File lib/markdown_render/parse.rb, line 61
def to_document(content)
  html = to_html(content)
  html = HTML.gsub('{{content}}', html)
  html.gsub('{{theme}}', @theme)
end
to_html(content) click to toggle source

takes markdown and returns html (as a string)

content - markdown content

# File lib/markdown_render/parse.rb, line 17
def to_html(content)
  case @parser
  when :kramdown, 'kramdown'
    require 'kramdown'
    Kramdown::Document.new(content).to_html
  when :redcarpet, 'redcarpet'
    require 'redcarpet'
    markdown = Redcarpet::Markdown.new(
      Redcarpet::Render::HTML,
      smart: true,
      no_intra_emphasis: true,
      fenced_code_blocks: true,
      autolink: true,
      tables: true,
      with_toc_data: true
    )

    # add smartypants support
    Redcarpet::Render::SmartyPants.render markdown.render(content)
  when :rdiscount, 'rdiscount'
    require 'rdiscount'
    RDiscount.new(content).to_html
  when :gfm, :github, :github_markdown, 'gfm', 'github_markdown'
    require 'github/markdown'
    GitHub::Markdown.render(content)
  end
end