class RedcarpetCompat

Creates an instance of Redcarpet with the RedCloth API.

Constants

EXTENSION_MAP
RENDERER_OPTIONS

Attributes

text[RW]

Public Class Methods

new(text, *exts) click to toggle source
# File lib/redcarpet/compat.rb, line 5
def initialize(text, *exts)
  exts_hash, render_hash = *parse_extensions_and_renderer_options(exts)
  @text = text
  renderer = Redcarpet::Render::HTML.new(render_hash)
  @markdown = Redcarpet::Markdown.new(renderer, exts_hash)
end

Public Instance Methods

to_html(*_dummy) click to toggle source
# File lib/redcarpet/compat.rb, line 12
def to_html(*_dummy)
  @markdown.render(text)
end

Private Instance Methods

list_to_truthy_hash(list) click to toggle source

Turns a list of symbols into a hash of symbol => true.

# File lib/redcarpet/compat.rb, line 66
def list_to_truthy_hash(list)
  list.inject({}) {|h, k| h[k] = true; h }
end
parse_extensions_and_renderer_options(exts) click to toggle source

Returns two hashes, the extensions and renderer options given the extension list

# File lib/redcarpet/compat.rb, line 59
def parse_extensions_and_renderer_options(exts)
  exts = rename_extensions(exts)
  exts.partition {|ext| !RENDERER_OPTIONS.include?(ext) }.
    map {|list| list_to_truthy_hash(list) }
end
rename_extensions(exts) click to toggle source
# File lib/redcarpet/compat.rb, line 47
def rename_extensions(exts)
  exts.map do |old_name|
    if new_name = EXTENSION_MAP[old_name]
      new_name
    else
      old_name
    end
  end.compact
end