Sha256: 8b43beeb5fc0bc31fafe33d09c1720ffd5e62958955e0e643a14adc53a5837e0

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'malt/engines/abstract'
require 'malt/formats/rdoc'
require 'malt/formats/html'

module Malt::Engine

  # Discount Markdown implementation.
  #
  #   http://github.com/rtomayko/rdiscount
  #
  # The +:smart+ and +:filter_html+ options can be set true
  # to enable those flags on the underlying RDiscount object.
  class RDiscount < Abstract

    default :markdown, :md

    # Convert Markdown text to HTML text.
    def render(params)
      case params[:to]
      when :html, nil
        intermediate(params).to_html
      else
        super(params)
      end
    end

    # Convert Markdown text to intermediate engine object.
    def intermediate(params)
      text = params[:text]
      ::RDiscount.new(text, *flags)
    end

    private

    # Load rdoc makup library if not already loaded.
    def initialize_engine
      return if defined? ::RDiscount
      require_library 'rdiscount'
    end

    #
    def flags(params={})
      [:smart, :filter_html].select{ |flag| params[flag] || settings[flag] }
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
malt-0.3.0 lib/malt/engines/rdiscount.rb
malt-0.2.0 lib/malt/engines/rdiscount.rb