summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarat Radchenko <marat@slonopotamus.org>2020-07-26 16:19:02 +0300
committerGitHub <noreply@github.com>2020-07-26 16:19:02 +0300
commitf4dfbca5dc1ddbedda136252184c0eb1294fb129 (patch)
treef8f4d9eec84d8150fb472bf3ff7c1c66e0aeeaf1
parent3697bd99a66293867edbc37cf6c2fbebf143893d (diff)
resolves #353 gracefully handle invalid `:front-cover-image:` value (#354)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor-epub3/converter.rb12
-rw-r--r--spec/image_spec.rb5
3 files changed, 12 insertions, 6 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index d9baee8..0cf8af9 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -14,6 +14,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* initial landmarks support: appendix, bibliography, bodymatter, cover, frontmatter, glossary, index, preface, toc (#174)
* add support for MathML (#10)
* rescale color palette to use darker shades of gray (#338)
+* gracefully handle invalid `:front-cover-image:` value (#353)
== 1.5.0.alpha.17 (2020-05-25) - @slonopotamus
diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb
index e4eadea..23fb1c8 100644
--- a/lib/asciidoctor-epub3/converter.rb
+++ b/lib/asciidoctor-epub3/converter.rb
@@ -1349,19 +1349,19 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
workdir = doc.attr 'docdir'
workdir = '.' if workdir.nil_or_empty?
- unless ::File.readable? ::File.join(workdir, image_path)
- logger.error %(#{::File.basename doc.attr('docfile')}: front cover image not found or readable: #{::File.expand_path image_path, workdir})
+ begin
+ @book.add_item(image_href, content: File.join(workdir, image_path)).cover_image
+ rescue => e
+ logger.error %(#{::File.basename doc.attr('docfile')}: error adding front cover image. Make sure that :front-cover-image: attribute points to a valid image file. #{e})
return nil
end
+ return nil if @format == :kf8
+
unless !image_attrs.empty? && (width = image_attrs['width']) && (height = image_attrs['height'])
width, height = 1050, 1600
end
- @book.add_item(image_href, content: File.join(workdir, image_path)).cover_image
-
- return nil if @format == :kf8
-
# NOTE SVG wrapper maintains aspect ratio and confines image to view box
content = %(<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index af2c6b7..3e8d9a7 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -46,6 +46,11 @@ describe 'Asciidoctor::Epub3::Converter - Image' do
expect(cover_page.content).to include '<image width="1050" height="1600" xlink:href="jacket/cover.png"/>'
end
+ it "doesn't crash if cover image points to a directory" do
+ book, = to_epub fixture_file('empty.adoc'), attributes: { 'front-cover-image' => '' }
+ expect(book).not_to be_nil
+ end
+
it 'supports image width/height' do
book, = to_epub fixture_file('image-dimensions/book.adoc')
chapter = book.item_by_href '_chapter.xhtml'