Sha256: de57c41678772c6214eb45856420ebab71cb879ec2727ebd81e0ba666d69e981

Contents?: true

Size: 518 Bytes

Versions: 4

Compression:

Stored size: 518 Bytes

Contents

# frozen_string_literal: true

class HTMLPipeline
  class TextFilter
    # HTML Filter that converts image's url into <img> tag.
    # For example, it will convert
    #   http://example.com/test.jpg
    # into
    #   <img src="http://example.com/test.jpg" alt=""/>.

    class ImageFilter < TextFilter
      def call(text, context: {}, result: {})
        text.gsub(%r{(https|http)?://.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i) do |match|
          %(<img src="#{match}" alt=""/>)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
html-pipeline-3.2.2 lib/html_pipeline/text_filter/image_filter.rb
html-pipeline-3.2.1 lib/html_pipeline/text_filter/image_filter.rb
html-pipeline-3.2.0 lib/html_pipeline/text_filter/image_filter.rb
html-pipeline-3.1.1 lib/html_pipeline/text_filter/image_filter.rb