Sha256: 01087555c1ab8fe0a1b37899be647096eee29fcf5140a18987e1ba69398ade0e

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

require "redcarpet"

module Middleman
  module Renderers

    class RedcarpetTemplate < ::Tilt::RedcarpetTemplate::Redcarpet2
      
      # Overwrite built-in Tilt version. 
      # Don't overload :renderer option with smartypants
      # Supper renderer-level options
      def generate_renderer
        return options.delete(:renderer) if options.has_key?(:renderer)
        
        # Pick a renderer
        renderer = ::Redcarpet::Render::HTML
        
        # Support SmartyPants
        if options.delete(: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]
      
        render_options = possible_render_opts.inject({}) do |sum, opt|
          sum[opt] = options.delete(opt) if options.has_key?(opt)
          sum
        end
        
        renderer.new(render_options)
      end
    end
   
    ::Tilt.register RedcarpetTemplate, 'markdown', 'mkd', 'md'
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
middleman-core-3.0.0 lib/middleman-core/renderers/redcarpet.rb
middleman-core-3.0.0.rc.4 lib/middleman-core/renderers/redcarpet.rb
middleman-core-3.0.0.rc.3 lib/middleman-core/renderers/redcarpet.rb
middleman-core-3.0.0.rc.2 lib/middleman-core/renderers/redcarpet.rb
middleman-core-3.0.0.rc.1 lib/middleman-core/renderers/redcarpet.rb