# File lib/asciidoctor/abstract_node.rb, line 347
  def generate_data_uri(target_image, asset_dir_key = nil)
    ext = ::File.extname target_image
    # QUESTION what if ext is empty?
    mimetype = (ext == '.svg' ? 'image/svg+xml' : %(image/#{ext[1..-1]}))
    if asset_dir_key
      image_path = normalize_system_path(target_image, @document.attr(asset_dir_key), nil, :target_name => 'image')
    else
      image_path = normalize_system_path(target_image)
    end

    unless ::File.readable? image_path
      warn %(asciidoctor: WARNING: image to embed not found or not readable: #{image_path})
      # must enclose string following return in " for Opal
      return "data:#{mimetype}:base64,"
      # uncomment to return 1 pixel white dot instead
      #return 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
    end

    bindata = nil
    if ::IO.respond_to? :binread
      bindata = ::IO.binread(image_path)
    else
      bindata = ::File.open(image_path, 'rb') {|file| file.read }
    end
    # NOTE base64 is autoloaded by reference to ::Base64
    %(data:#{mimetype};base64,#{::Base64.encode64(bindata).delete EOL})
  end