Sha256: 73d7da6efb2c6939594cfdb7aa76e915f1574f34e5d7e5fe7c112baae0aa1946

Contents?: true

Size: 849 Bytes

Versions: 11

Compression:

Stored size: 849 Bytes

Contents

# frozen_string_literal: true

HTMLPipeline.require_dependency("commonmarker", "MarkdownFilter")

class HTMLPipeline
  class ConvertFilter
    # HTML Filter that converts Markdown text into HTML.
    #
    # Context options:
    #   :markdown[:parse] => Commonmarker parse options
    #   :markdown[:render] => Commonmarker render options
    #   :markdown[:extensions] => Commonmarker extensions options
    class MarkdownFilter < ConvertFilter
      def initialize(context: {}, result: {})
        super(context: context, result: result)
      end

      # Convert Commonmark to HTML using the best available implementation.
      def call(text)
        options = @context.fetch(:markdown, {})
        plugins = options.fetch(:plugins, {})
        Commonmarker.to_html(text, options: options, plugins: plugins).rstrip!
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
html-pipeline-3.1.1 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.1.0 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.3 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.2 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.1 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0.pre6 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0.pre5 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0.pre3 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0.pre2 lib/html_pipeline/convert_filter/markdown_filter.rb
html-pipeline-3.0.0.pre1 lib/html_pipeline/convert_filter/markdown_filter.rb