Sha256: ee07fe88900c2173ac7d94212e5470bde5fd3dfa49a93b2252f858fa8bb5dd9a

Contents?: true

Size: 1.12 KB

Versions: 169

Compression:

Stored size: 1.12 KB

Contents

require 'tilt/template'
require 'pandoc-ruby'

module Tilt
  # Pandoc markdown implementation. See:
  # http://pandoc.org/
  class PandocTemplate < Template
    self.default_mime_type = 'text/html'

    def tilt_to_pandoc_mapping
      { :smartypants => :smart,
        :escape_html => { :f => 'markdown-raw_html' },
        :commonmark => { :f => 'commonmark' },
        :markdown_strict => { :f => 'markdown_strict' }
      }
    end

    # turn options hash into an array
    # Map tilt options to pandoc options
    # Replace hash keys with value true with symbol for key
    # Remove hash keys with value false
    # Leave other hash keys untouched
    def pandoc_options
      options.reduce([]) do |sum, (k,v)|
        case v
        when true
          sum << (tilt_to_pandoc_mapping[k] || k)
        when false
          sum
        else
          sum << { k => v }
        end
      end
    end

    def prepare
      @engine = PandocRuby.new(data, *pandoc_options)
      @output = nil
    end

    def evaluate(scope, locals, &block)
      @output ||= @engine.to_html.strip
    end

    def allows_script?
      false
    end
  end
end

Version data entries

169 entries across 132 versions & 23 rubygems

Version Path
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/pandoc.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
brakeman-4.10.1 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
brakeman-5.0.0.pre1 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
brakeman-4.10.0 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
brakeman-4.9.1 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/pandoc.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/pandoc.rb
brakeman-4.9.0 bundle/ruby/2.7.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.9/lib/tilt/pandoc.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/tilt-2.0.10/lib/tilt/pandoc.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/tilt-2.0.9/lib/tilt/pandoc.rb