Sha256: 4aa8f8654ccb0fe09269b261c59213a738aaadf66ca4c68b990560d9988ae1f2

Contents?: true

Size: 435 Bytes

Versions: 2

Compression:

Stored size: 435 Bytes

Contents

# frozen_string_literal: true

module AutoHtml
  # Image filter
  class Image
    def initialize(proxy: nil, alt: nil)
      @proxy = proxy || ''
      @alt = alt
    end

    def call(text)
      text.gsub(image_pattern) do |match|
        TagHelper.tag(:img, src: @proxy + match, alt: @alt)
      end
    end

    private

    def image_pattern
      %r{(?<!src=")https?://.+?\.(jpg|jpeg|bmp|gif|png|svg)(\?\S+)?}i
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auto_html-2.1.1 lib/auto_html/image.rb
auto_html-2.1.0 lib/auto_html/image.rb