File: image_filter.rb

package info (click to toggle)
ruby-html-pipeline 2.14.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: ruby: 2,265; sh: 13; makefile: 6
file content (19 lines) | stat: -rw-r--r-- 479 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module HTML
  class Pipeline
    # 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.gsub(/(https|http)?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
          %(<img src="#{match}" alt=""/>)
        end
      end
    end
  end
end