Sha256: 112e482d70206ded8b62680f760a159920417aecb01c3c5b6a0d56a8f13ff98f

Contents?: true

Size: 1.72 KB

Versions: 17

Compression:

Stored size: 1.72 KB

Contents

require 'tilt/template'
require 'commonmarker'

module Tilt
  class CommonMarkerTemplate < Template
    self.default_mime_type = 'text/html'

    OPTION_ALIAS = {
      :smartypants => :SMART
    }
    PARSE_OPTIONS = [
      :FOOTNOTES,
      :LIBERAL_HTML_TAG,
      :SMART,
      :smartypants,
      :STRIKETHROUGH_DOUBLE_TILDE,
      :UNSAFE,
      :VALIDATE_UTF8,
    ].freeze
    RENDER_OPTIONS = [
      :FOOTNOTES,
      :FULL_INFO_STRING,
      :GITHUB_PRE_LANG,
      :HARDBREAKS,
      :NOBREAKS,
      :SAFE, # Removed in v0.18.0 (2018-10-17)
      :SOURCEPOS,
      :TABLE_PREFER_STYLE_ATTRIBUTES,
      :UNSAFE,
    ].freeze
    EXTENSIONS = [
      :autolink,
      :strikethrough,
      :table,
      :tagfilter,
      :tasklist,
    ].freeze

    def extensions
      EXTENSIONS.select do |extension|
        options[extension]
      end
    end

    def parse_options
      raw_options = PARSE_OPTIONS.select do |option|
        options[option]
      end
      actual_options = raw_options.map do |option|
        OPTION_ALIAS[option] || option
      end

      if actual_options.any?
        actual_options
      else
        :DEFAULT
      end
    end

    def render_options
      raw_options = RENDER_OPTIONS.select do |option|
        options[option]
      end
      actual_options = raw_options.map do |option|
        OPTION_ALIAS[option] || option
      end
      if actual_options.any?
        actual_options
      else
        :DEFAULT
      end
    end

    def prepare
      @engine = nil
      @output = nil
    end

    def evaluate(scope, locals, &block)
      doc = CommonMarker.render_doc(data, parse_options, extensions)
      doc.to_html(render_options, extensions)
    end

    def allows_script?
      false
    end
  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
brakeman-6.1.2 bundle/ruby/3.3.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-6.1.1 bundle/ruby/3.0.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-6.1.0 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-6.0.1 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-6.0.0 bundle/ruby/3.0.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-5.4.1 bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
tilt-2.1.0 lib/tilt/commonmarker.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-5.4.0 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-5.3.1 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
brakeman-5.3.0 bundle/ruby/2.7.0/gems/tilt-2.0.11/lib/tilt/commonmarker.rb
tilt-2.0.11 lib/tilt/commonmarker.rb