Sha256: 9f8b86e4cd7634e662d8b7c17a1da3246b2e90856de889665fc1a1b92ab385d9

Contents?: true

Size: 951 Bytes

Versions: 15

Compression:

Stored size: 951 Bytes

Contents

require 'github/markdown'

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

15 entries across 15 versions & 3 rubygems

Version Path
html-pipeline-0.3.1 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.3.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.2.1 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.2.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.1.0 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.14 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.13 lib/html/pipeline/markdown_filter.rb
geothird-html-pipeline-0.0.12 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.12 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.11 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.10 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.8 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.7 lib/html/pipeline/markdown_filter.rb
html-pipeline-no-charlock-0.0.6 lib/html/pipeline/markdown_filter.rb
html-pipeline-0.0.6 lib/html/pipeline/markdown_filter.rb