Sha256: fa603058baec670d4643df43512ffd5a69441a0a67df043ff6d974c445e79b1c

Contents?: true

Size: 1.06 KB

Versions: 42

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'kramdown'
module Thredded
  module HtmlPipeline
    class KramdownFilter < ::HTML::Pipeline::TextFilter
      class << self
        attr_accessor :options
      end

      # See http://kramdown.gettalong.org/options.html
      self.options = {
        input: 'GFM',
        gfm_quirks: 'paragraph_end',
        # Smart quotes conflict with @"at mentions". Disable smart quotes.
        smart_quotes: %w[apos apos quot quot],
        remove_block_html_tags: false,
        syntax_highlighter: nil
      }

      def initialize(text, context = nil, result = nil)
        super text, context, result
        if @text.frozen?
          @text = @text.delete("\r")
        else
          @text.delete! "\r"
        end
      end

      # Convert Markdown to HTML using the best available implementation
      # and convert into a DocumentFragment.
      def call
        result = Kramdown::Document.new(@text, self.class.options.deep_merge(context[:kramdown_options] || {})).to_html
        result.rstrip!
        result
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
thredded-1.1.0 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-1.0.1 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-1.0.0 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.16 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.15 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.14 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.13 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.12 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.11 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.10 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.9 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.8 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.7 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.6 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.5 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.4 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.3 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.1 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.16.0 lib/thredded/html_pipeline/kramdown_filter.rb
thredded-0.15.5 lib/thredded/html_pipeline/kramdown_filter.rb