Sha256: aef7a3c47e111d393272ef54636f421d5baf777bc97d63f803558e50d6f8a0d1

Contents?: true

Size: 1.06 KB

Versions: 37

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Asciidoctor
  module Image
    DataUriRx = %r(^data:image/(?<fmt>png|jpe?g|gif|pdf|bmp|tiff|svg\+xml);base64,(?<data>.*)$)
    FormatAliases = { 'jpg' => 'jpeg', 'svg+xml' => 'svg' }

    def self.format image_path
      ((ext = ::File.extname image_path).downcase.slice 1, ext.length)
    end

    def self.target_and_format image_path, attributes = nil
      if (image_path.start_with? 'data:') && (m = DataUriRx.match image_path)
        [(m[:data].extend ::Base64), (FormatAliases.fetch m[:fmt], m[:fmt])]
      else
        [image_path, attributes&.[]('format') || ((ext = ::File.extname image_path).downcase.slice 1, ext.length)]
      end
    end

    def target_and_format
      image_path = inline? ? target : (attr 'target')
      if (image_path.start_with? 'data:') && (m = DataUriRx.match image_path)
        [(m[:data].extend ::Base64), (FormatAliases.fetch m[:fmt], m[:fmt])]
      else
        [image_path, (attr 'format', nil, false) || ((ext = ::File.extname image_path).downcase.slice 1, ext.length)]
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.3.13 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.12 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.11 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.10 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.9 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.8 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.7 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.6 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.5 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.4 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.3 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.2 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.1 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.3.0 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.2.0 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.1.6 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.1.5 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.1.4 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.1.3 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-2.1.2 lib/asciidoctor/pdf/ext/asciidoctor/image.rb