Sha256: 30a75c2fa042728f302e1e766f29bc4703b0908a906ae14f0ad98f88ed618b05

Contents?: true

Size: 825 Bytes

Versions: 5

Compression:

Stored size: 825 Bytes

Contents

module Convert
  module Converters

    # Vimeo and Youtube embed markdown extension
    def video_embed(string, options = {})
      @regex = /\?\[(youtube|vimeo)\]\(https?:\/\/(www\.)?(vimeo\.com\/|youtu\.be\/|youtube\.com\/watch\?v=)(\S+)\)/

      string.scan(@regex).each do |type, prefix, url, id|
        r = if('vimeo' == type)
          vimeo_embed(options)
        elsif('youtube' == type)
          youtube_embed(options)
        else
          nil
        end
        # Substitute the original text with the embedded version
        # OLD, optional https not supported:
        # @text.gsub!("?[#{type}](https://#{prefix}#{url}#{id})", r) if r
        x = %r{\?\[#{type}\]\(https?:\/\/#{Regexp.escape(prefix)}#{Regexp.escape(url)}#{id}\)}i
        string.gsub!(x, r) if r
      end
      string
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
convert-0.1.7 lib/converters/video_embed.rb
convert-0.1.6 lib/converters/video_embed.rb
convert-0.1.5 lib/converters/video_embed.rb
convert-0.1.4 lib/converters/video_embed.rb
convert-0.1.3 lib/converters/video_embed.rb