asciidoctor-epub3 1.5.0.alpha.19 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -227,8 +227,8 @@ module Asciidoctor
227
227
  # https://idpf.github.io/epub-vocabs/structure/
228
228
  landmarks = []
229
229
 
230
- cover_page = add_cover_page node
231
- landmarks << { type: 'cover', href: cover_page.href, title: 'Cover' } unless cover_page.nil?
230
+ front_cover = add_cover_page node, 'front-cover'
231
+ landmarks << { type: 'cover', href: front_cover.href, title: 'Front Cover' } unless front_cover.nil?
232
232
 
233
233
  front_matter_page = add_front_matter_page node
234
234
  landmarks << { type: 'frontmatter', href: front_matter_page.href, title: 'Front Matter' } unless front_matter_page.nil?
@@ -253,6 +253,9 @@ module Asciidoctor
253
253
  add_chapter node
254
254
  end
255
255
 
256
+ _back_cover = add_cover_page node, 'back-cover'
257
+ # TODO: add landmark for back cover? But what epub:type?
258
+
256
259
  landmarks << { type: 'bodymatter', href: %(#{get_chapter_name toc_items[0]}.xhtml), title: 'Start of Content' } unless toc_items.empty?
257
260
 
258
261
  toc_items.each do |item|
@@ -992,12 +995,21 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
992
995
  img_attrs = []
993
996
  img_attrs << %(alt="#{node.attr 'alt'}") if node.attr? 'alt'
994
997
 
995
- width = node.attr 'scaledwidth'
996
- width = node.attr 'width' if width.nil?
997
-
998
998
  # Unlike browsers, Calibre/Kindle *do* scale image if only height is specified
999
999
  # So, in order to match browser behavior, we just always omit height
1000
- img_attrs << %(width="#{width}") unless width.nil?
1000
+
1001
+ if (scaledwidth = node.attr 'scaledwidth')
1002
+ img_attrs << %(style="width: #{scaledwidth}")
1003
+ elsif (width = node.attr 'width')
1004
+ # HTML5 spec (and EPUBCheck) only allows pixels in width, but browsers also accept percents
1005
+ # and there are multiple AsciiDoc files in the wild that have width=percents%
1006
+ # So, for compatibility reasons, output percentage width as a CSS style
1007
+ if width[/^\d+%$/]
1008
+ img_attrs << %(style="width: #{width}")
1009
+ else
1010
+ img_attrs << %(width="#{width}")
1011
+ end
1012
+ end
1001
1013
 
1002
1014
  img_attrs
1003
1015
  end
@@ -1338,20 +1350,22 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
1338
1350
  nil
1339
1351
  end
1340
1352
 
1341
- def add_cover_page doc
1342
- return nil if (image_path = doc.attr 'front-cover-image').nil?
1353
+ def add_cover_page doc, name
1354
+ image_attr_name = %(#{name}-image)
1355
+
1356
+ return nil if (image_path = doc.attr image_attr_name).nil?
1343
1357
 
1344
1358
  imagesdir = (doc.attr 'imagesdir', '.').chomp '/'
1345
1359
  imagesdir = (imagesdir == '.' ? '' : %(#{imagesdir}/))
1346
1360
 
1347
1361
  image_attrs = {}
1348
1362
  if (image_path.include? ':') && image_path =~ ImageMacroRx
1349
- logger.warn %(deprecated block macro syntax detected in front-cover-image attribute) if image_path.start_with? 'image::'
1363
+ logger.warn %(deprecated block macro syntax detected in :#{image_attr_name}: attribute) if image_path.start_with? 'image::'
1350
1364
  image_path = %(#{imagesdir}#{$1})
1351
1365
  (::Asciidoctor::AttributeList.new $2).parse_into image_attrs, %w(alt width height) unless $2.empty?
1352
1366
  end
1353
1367
 
1354
- image_href = %(#{imagesdir}jacket/cover#{::File.extname image_path})
1368
+ image_href = %(#{imagesdir}jacket/#{name}#{::File.extname image_path})
1355
1369
 
1356
1370
  workdir = doc.attr 'docdir'
1357
1371
  workdir = '.' if workdir.nil_or_empty?
@@ -1359,7 +1373,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
1359
1373
  begin
1360
1374
  @book.add_item(image_href, content: File.join(workdir, image_path)).cover_image
1361
1375
  rescue => e
1362
- 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})
1376
+ logger.error %(#{::File.basename doc.attr('docfile')}: error adding cover image. Make sure that :#{image_attr_name}: attribute points to a valid image file. #{e})
1363
1377
  return nil
1364
1378
  end
1365
1379
 
@@ -1400,7 +1414,7 @@ body > svg {
1400
1414
  </svg></body>
1401
1415
  </html>).to_ios
1402
1416
 
1403
- @book.add_ordered_item 'cover.xhtml', content: content, id: 'cover'
1417
+ @book.add_ordered_item %(#{name}.xhtml), content: content, id: name
1404
1418
  end
1405
1419
 
1406
1420
  def get_frontmatter_files doc, workdir
@@ -1644,8 +1658,15 @@ body > svg {
1644
1658
  return [result]
1645
1659
  end
1646
1660
 
1647
- logger.debug 'Using KindleGen from PATH'
1648
- [%(kindlegen#{::Gem.win_platform? ? '.exe' : ''})]
1661
+ begin
1662
+ require 'kindlegen' unless defined? ::Kindlegen
1663
+ result = ::Kindlegen.command.to_s
1664
+ logger.debug %(Using KindleGen from gem: #{result})
1665
+ [result]
1666
+ rescue LoadError => e
1667
+ logger.debug %(#{e}; Using KindleGen from PATH)
1668
+ [%(kindlegen#{::Gem.win_platform? ? '.exe' : ''})]
1669
+ end
1649
1670
  end
1650
1671
 
1651
1672
  def distill_epub_to_mobi epub_file, target, compress
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Epub3
5
- VERSION = '1.5.0.alpha.19'
5
+ VERSION = '1.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-epub3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.alpha.19
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-21 00:00:00.000000000 Z
12
+ date: 2021-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asciidoctor-diagram
@@ -65,14 +65,14 @@ dependencies:
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.0
68
+ version: 2.2.0
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.2.0
75
+ version: 2.2.0
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rake
78
78
  requirement: !ruby/object:Gem::Requirement
@@ -107,14 +107,14 @@ dependencies:
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 3.9.0
110
+ version: 3.10.0
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 3.9.0
117
+ version: 3.10.0
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: rubocop
120
120
  requirement: !ruby/object:Gem::Requirement
@@ -135,14 +135,14 @@ dependencies:
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.38.0
138
+ version: 1.41.0
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.38.0
145
+ version: 1.41.0
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: asciidoctor
148
148
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +194,7 @@ dependencies:
194
194
  description: 'An extension for Asciidoctor that converts AsciiDoc documents to EPUB3
195
195
  and KF8/MOBI (Kindle) e-book archives.
196
196
 
197
- '
197
+ '
198
198
  email: dan@opendevise.com
199
199
  executables:
200
200
  - asciidoctor-epub3
@@ -280,14 +280,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
280
  requirements:
281
281
  - - ">="
282
282
  - !ruby/object:Gem::Version
283
- version: 2.3.0
283
+ version: 2.4.0
284
284
  required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  requirements:
286
- - - ">"
286
+ - - ">="
287
287
  - !ruby/object:Gem::Version
288
- version: 1.3.1
288
+ version: '0'
289
289
  requirements: []
290
- rubygems_version: 3.1.4
290
+ rubygems_version: 3.2.15
291
291
  signing_key:
292
292
  specification_version: 4
293
293
  summary: Converts AsciiDoc documents to EPUB3 and KF8/MOBI (Kindle) e-book formats