Class: Middleman::Renderers::RedcarpetTemplate

Inherits:
Tilt::RedcarpetTemplate::Redcarpet2
  • Object
show all
Defined in:
lib/middleman-core/renderers/redcarpet.rb

Constant Summary collapse

ALIASES =

because tilt has decided to convert these in the wrong direction

{
  escape_html: :filter_html
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ RedcarpetTemplate

Returns a new instance of RedcarpetTemplate.



13
14
15
16
17
# File 'lib/middleman-core/renderers/redcarpet.rb', line 13

def initialize(*args, &block)
  super

  @context = @options[:context] if @options.key?(:context)
end

Instance Method Details

#evaluate(scope, _) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/middleman-core/renderers/redcarpet.rb', line 47

def evaluate(scope, _)
  @output ||= begin
    MiddlemanRedcarpetHTML.scope = @context || scope

    @engine.render(data)
  end
end

#generate_rendererObject

Overwrite built-in Tilt version. Don't overload :renderer option with smartypants Support renderer-level options



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/middleman-core/renderers/redcarpet.rb', line 22

def generate_renderer
  return options.delete(:renderer) if options.key?(:renderer)

  covert_options_to_aliases!

  # Pick a renderer
  renderer = MiddlemanRedcarpetHTML

  if options.delete(:smartypants)
    # Support SmartyPants
    renderer = Class.new(renderer) do
      include ::Redcarpet::Render::SmartyPants
    end
  end

  # Renderer Options
  possible_render_opts = [:filter_html, :no_images, :no_links, :no_styles, :safe_links_only, :with_toc_data, :hard_wrap, :xhtml, :prettify, :link_attributes]

  render_options = possible_render_opts.each_with_object({}) do |opt, sum|
    sum[opt] = options.delete(opt) if options.key?(opt)
  end

  renderer.new(render_options)
end