Sha256: c8f98c29c406ebab659bea6ed46901db6f2073d07b62310ceb5238651f8437fb

Contents?: true

Size: 948 Bytes

Versions: 3

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

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

    class << self
      def format path, attributes = nil
        (attributes && attributes['format']) || ((ext = ::File.extname path).downcase.slice 1, ext.length)
      end
    end

    def format
      (attr 'format', nil, false) || ((ext = ::File.extname(inline? ? target : (attr 'target'))).downcase.slice 1, ext.length)
    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

3 entries across 3 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.5.0.rc.3 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-1.5.0.rc.2 lib/asciidoctor/pdf/ext/asciidoctor/image.rb
asciidoctor-pdf-1.5.0.rc.1 lib/asciidoctor/pdf/ext/asciidoctor/image.rb