Sha256: 147454d1746458602f0a5be7ee1a759d55a97d5b0bbcd07f7fd2d1b6fce06345

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

begin
  require "github/markdown"
rescue LoadError => _
  abort "Missing dependency 'github-markdown' for MarkdownFilter. See README.md for details."
end

module HTML
  class Pipeline
    # HTML Filter that converts Markdown text into HTML and converts into a
    # DocumentFragment. This is different from most filters in that it can take a
    # non-HTML as input. It must be used as the first filter in a pipeline.
    #
    # Context options:
    #   :gfm      => false    Disable GFM line-end processing
    #
    # This filter does not write any additional information to the context hash.
    class MarkdownFilter < TextFilter
      def initialize(text, context = nil, result = nil)
        super text, context, result
        @text = @text.gsub "\r", ''
      end

      # Convert Markdown to HTML using the best available implementation
      # and convert into a DocumentFragment.
      def call
        mode = (context[:gfm] != false) ? :gfm : :markdown
        html = GitHub::Markdown.to_html(@text, mode)
        html.rstrip!
        html
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
html-pipeline-2.2.2 lib/html/pipeline/markdown_filter.rb
html-pipeline-2.2.1 lib/html/pipeline/markdown_filter.rb
html-pipeline-2.2.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-2.1.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-2.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.11.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.10.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.9.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.8.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.7.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.6.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.5.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.4.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.3.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.1.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-1.0.0 lib/html/pipeline/markdown_filter.rb