def read_contents target, opts = {}
doc = @document
if (Helpers.uriish? target) || ((start = opts[:start]) && (Helpers.uriish? start) &&
(target = (@path_resolver ||= PathResolver.new).web_path target, start))
if doc.attr? 'allow-uri-read'
Helpers.require_library 'open-uri/cached', 'open-uri-cached' if doc.attr? 'cache-uri'
begin
data = ::OpenURI.open_uri(target) {|fd| fd.read }
data = (Helpers.normalize_lines_from_string data) * LF if opts[:normalize]
rescue
warn %(asciidoctor: WARNING: could not retrieve contents of #{opts[:label] || 'asset'} at URI: #{target}) if opts.fetch :warn_on_failure, true
data = nil
end
else
warn %(asciidoctor: WARNING: cannot retrieve contents of #{opts[:label] || 'asset'} at URI: #{target} (allow-uri-read attribute not enabled)) if opts.fetch :warn_on_failure, true
data = nil
end
else
target = normalize_system_path target, opts[:start], nil, :target_name => (opts[:label] || 'asset')
data = read_asset target, :normalize => opts[:normalize], :warn_on_failure => (opts.fetch :warn_on_failure, true), :label => opts[:label]
end
data
end