summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarat Radchenko <marat@slonopotamus.org>2020-05-18 11:27:52 +0300
committerGitHub <noreply@github.com>2020-05-18 11:27:52 +0300
commit6f876a571563cad1901da3c42312b76ee97e3846 (patch)
tree9d6961f6375e4fce4242522a5a666dd687466127
parenta63c83eb15db0a5b7e75f6f87a28094ba2beba1d (diff)
resolves #334 add remote media URLs to EPUB manifest (#335)
-rw-r--r--CHANGELOG.adoc2
-rw-r--r--lib/asciidoctor-epub3/converter.rb19
-rw-r--r--spec/converter_spec.rb30
3 files changed, 42 insertions, 9 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index e0079d9..6d5f869 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -7,7 +7,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
== Unreleased
-* support remote URLs for audio/video/image (#333)
+* support remote URLs for audio/video/image (#333, #334)
== 1.5.0.alpha.16 (2020-04-26) - @slonopotamus
diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb
index b24fdef..70a725b 100644
--- a/lib/asciidoctor-epub3/converter.rb
+++ b/lib/asciidoctor-epub3/converter.rb
@@ -244,7 +244,7 @@ module Asciidoctor
@media_files.each do |file|
if file[:name].start_with? %(#{docimagesdir}jacket/cover.)
logger.warn %(path is reserved for cover artwork: #{file[:name]}; skipping file found in content)
- elsif ::File.readable? file[:path]
+ elsif file[:path].nil? || File.readable?(file[:path])
mime_types = MIME::Types.type_for file[:name]
mime_types.delete_if {|x| x.media_type != file[:media_type] }
preferred_mime_type = mime_types.empty? ? nil : mime_types[0].content_type
@@ -930,13 +930,16 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
epub_properties << 'svg' unless epub_properties.include? 'svg'
end
- return if Asciidoctor::Helpers.uriish? target
-
- out_dir = node.attr('outdir', nil, true) || doc_option(node.document, :to_dir)
- fs_path = (::File.join out_dir, target)
- unless ::File.exist? fs_path
- base_dir = root_document(node.document).base_dir
- fs_path = ::File.join base_dir, target
+ if Asciidoctor::Helpers.uriish? target
+ # We need to add both local and remote media files to manifect
+ fs_path = nil
+ else
+ out_dir = node.attr('outdir', nil, true) || doc_option(node.document, :to_dir)
+ fs_path = (::File.join out_dir, target)
+ unless ::File.exist? fs_path
+ base_dir = root_document(node.document).base_dir
+ fs_path = ::File.join base_dir, target
+ end
end
# We need *both* virtual and physical image paths. Unfortunately, references[:images] only has one of them.
@media_files << { name: target, path: fs_path, media_type: media_type }
diff --git a/spec/converter_spec.rb b/spec/converter_spec.rb
index 3d1e24e..2ac2cb7 100644
--- a/spec/converter_spec.rb
+++ b/spec/converter_spec.rb
@@ -249,6 +249,21 @@ text3
expect(video.media_type).to eq('video/webm')
end
+ it 'supports remote video' do
+ book, = to_epub <<~EOS
+= Article
+
+video::http://nonexistent/small.webm[]
+ EOS
+ article = book.item_by_href '_article.xhtml'
+ expect(article).not_to be_nil
+ expect(article['properties']).to include('remote-resources')
+ expect(article.content).to include '<video src="http://nonexistent/small.webm" controls="controls">'
+ video = book.item_by_href 'http://nonexistent/small.webm'
+ expect(video).not_to be_nil
+ expect(video.media_type).to eq('video/webm')
+ end
+
it 'supports audio' do
book, = to_epub fixture_file('audio/book.adoc')
chapter = book.item_by_href '_chapter.xhtml'
@@ -259,6 +274,21 @@ text3
expect(audio.media_type).to eq('audio/mpeg')
end
+ it 'supports remote audio' do
+ book, = to_epub <<~EOS
+= Article
+
+audio::http://nonexistent/small.mp3[]
+ EOS
+ article = book.item_by_href '_article.xhtml'
+ expect(article).not_to be_nil
+ expect(article['properties']).to include('remote-resources')
+ expect(article.content).to include '<audio src="http://nonexistent/small.mp3" controls="controls">'
+ audio = book.item_by_href 'http://nonexistent/small.mp3'
+ expect(audio).not_to be_nil
+ expect(audio.media_type).to eq('audio/mpeg')
+ end
+
it 'supports horizontal dlist' do
book = to_epub <<~EOS
= Article