Sha256: 8aa9f7ae4ba5f75847415c6ee53e69f655968dfbb258d54ac9bcd67f62c962a8

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

begin
  require "commonmarker"
rescue LoadError => _
  raise HTML::Pipeline::MissingDependencyError, "Missing dependency 'commonmarker' 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
        options = [:GITHUB_PRE_LANG]
        options << :HARDBREAKS if context[:gfm] != false
        html = CommonMarker.render_html(@text, options, [:table, :strikethrough, :tagfilter, :autolink])
        html.rstrip!
        html
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
html-pipeline-2.6.0 lib/html/pipeline/markdown_filter.rb