asciidoctor-epub3 1.5.0.alpha.14 → 1.5.0.alpha.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61c778469422ef65c9ae4f3ca20cb326a61fca5fc4733eabd1eb8eb0a71f9c61
4
- data.tar.gz: 8bac1f2fba3b11504dfe5a4020445fe4b2d2b9c6a01ecad1d9c1a1c45eb4ee3a
3
+ metadata.gz: 4404201f6335840b7c6bb344eed4870654ae7132a3a63309d3a3f64536da62f2
4
+ data.tar.gz: 252e5083cc9a5e1d589181ee0b141414f7182867ba763a1927271d72779ab4e2
5
5
  SHA512:
6
- metadata.gz: b5663adeb39345f53a7e80f8f0b2ebdeb253bf70011fc1428e0322a63b9570d2ba539fa6595297e576445dc53b668f3da1dd463d9548cbcff2fca40d83fd75fe
7
- data.tar.gz: 3d54e7f7ab62cd37306552267a7bd315fb6c970d185cf976912c0a57aac24b7f315386dbcd1d7e1c67afb038f66a17281e73c27c3f92ecaaa416bbddad8a0d16
6
+ metadata.gz: e85119f2680e17c119d1997e9272e14630c64caae39c27a2055ec60cf617399d95154e1cf3de41f2eedebc9b73a373f2028c3c854cb1d779da3adfde3c79c0f8
7
+ data.tar.gz: ef099d1233ad69d99e0985ba6f9580d99f80ccdc824d036505f5507adf18fad79a8643684f111665d086147558a41eec4513db95be5d93d6e4d1bf46d35a3dba
@@ -5,6 +5,16 @@
5
5
  This document provides a high-level view of the changes to the {project-name} by release.
6
6
  For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
7
7
 
8
+ == 1.5.0.alpha.15 (2020-03-11) - @slonopotamus
9
+
10
+ * support section numbering and captions (#20)
11
+ * fix `\<<anchor,link text>>` to show link text (#317)
12
+ * add xref ids to paragraphs (#317)
13
+ * support syntax highlighting with CodeRay and Rouge (#262)
14
+ * pygments.rb is no longer auto-activated
15
+ * add series metadata (#307)
16
+ * fix Sony Reader crash (#152)
17
+
8
18
  == 1.5.0.alpha.14 (2020-02-29) - @slonopotamus
9
19
 
10
20
  * support conversion of article documents to a single-chapter file
data/Gemfile CHANGED
@@ -17,9 +17,4 @@ group :optional do
17
17
  # We would like to make kindlegen a runtime dependency, but can't because of the way asciidoctorj-epub3 packaging works
18
18
  # See https://github.com/asciidoctor/asciidoctor-epub3/issues/288
19
19
  gem 'kindlegen', '~> 3.0.3'
20
- gem 'pygments.rb', '1.2.1'
21
- end
22
-
23
- group :docs do
24
- gem 'yard', require: false
25
20
  end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014-2020 OpenDevise Inc. and the Asciidoctor Project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  = {project-name}: A _native_ EPUB3 converter for AsciiDoc
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
3
- v1.5.0.alpha.14, 2020-02-29
3
+ v1.5.0.alpha.15, 2020-03-11
4
4
  // Settings:
5
5
  :experimental:
6
6
  :idprefix:
@@ -50,7 +50,6 @@ endif::[]
50
50
 
51
51
  ifdef::status[]
52
52
  image:https://img.shields.io/gem/v/asciidoctor-epub3.svg[Latest Release,link={uri-gem}]
53
- image:https://img.shields.io/badge/license-MIT-blue.svg[MIT License,link=#copyright]
54
53
  image:{uri-repo}/workflows/CI/badge.svg[GitHub Actions,link={uri-ci}]
55
54
  endif::[]
56
55
 
@@ -103,7 +102,7 @@ Of course, there's always room for improvement, so we'll continue to work with y
103
102
  * EPUB3 metadata, manifest and spine (assembled by Gepub)
104
103
  * Document metadata (title, authors, subject, keywords, etc.)
105
104
  * Internal cross reference links
106
- * Syntax highlighting with CodeRay or Pygments (must use inline styles)
105
+ * Syntax highlighting with Rouge, CodeRay or Pygments
107
106
  * Unicode callout numbers
108
107
  * Page breaks avoided in block content (so much as it's supported by the e-reader)
109
108
  * Orphan section titles avoided (so much as it's supported by the e-reader)
@@ -160,7 +159,6 @@ Here's an example showing the structure of a book:
160
159
  Author Name
161
160
  :doctype: book
162
161
  :imagesdir: images
163
- \ifndef::ebook-format[:leveloffset: 1]
164
162
  //...and so on
165
163
 
166
164
  == Chapter One
@@ -198,26 +196,28 @@ You can install the published gem using the following command:
198
196
  This optional environment variable tells the gem installer to link against the C libraries on the system, if available, instead of compiling the libraries from scratch.
199
197
  This speeds up the installation of Nokogiri considerably.
200
198
 
201
- If you want to syntax highlight source listings, you'll also want to install CodeRay or Pygments.
199
+ If you want to syntax highlight source listings, you'll also want to install Rouge, CodeRay or Pygments.
202
200
  Choose one (or more) of the following:
203
201
 
202
+ .Rouge
203
+ $ gem install rouge
204
+
204
205
  .CodeRay
205
206
  $ gem install coderay
206
207
 
207
208
  .Pygments
208
209
  $ gem install pygments.rb
209
210
 
210
- You then activate syntax highlighting for a given document by adding the `source-highlighter` attribute to the document header (CodeRay shown):
211
+ You then activate syntax highlighting for a given document by adding the `source-highlighter` attribute to the document header (Rouge shown):
211
212
 
212
213
  [source,asciidoc]
213
214
  ----
214
- :source-highlighter: coderay
215
+ :source-highlighter: rouge
215
216
  ----
216
217
 
217
- NOTE: At the moment, Pygments is automatically used if it's available.
218
- If a style is not specified, the black and white theme (i.e., bw) is used.
219
- This default is used so that the syntax highlighting is legibile regardless of which reading mode the reader selects (white, black, sepia, etc).
220
- To override this default, you must pass a valid Pygments style name to the `pygments-style` attribute when invoking the `asciidoctor-epub3` script (e.g., `-a pygments-style=pastie`).
218
+ NOTE: If a style is not specified, the black and white theme (i.e., bw) is used.
219
+ This default is used so that the syntax highlighting is legible regardless of which reading mode the reader selects (white, black, sepia, etc).
220
+ To override this default, you must set `<highlighter>-style` document header attribute to a valid highlighter style name (e.g., `:rouge-style: pastie`).
221
221
 
222
222
  Assuming all the required gems install properly, verify you can run the `asciidoctor-epub3` script:
223
223
 
@@ -298,6 +298,10 @@ The recommended practice is to identify the referenced resource by means of a st
298
298
  |An optional override of the properties attribute for this document's item in the manifest.
299
299
  _Only applies to a chapter document._
300
300
 
301
+ |series-name, series-volume, series-id
302
+ |Populates the series statements (`belongs-to-collection`) in the package metadata.
303
+ Volume is a number, ID probably a UUID that is constant for all volumes in the series.
304
+
301
305
  |epub3-frontmatterdir
302
306
  |The path to a directory that contains frontmatter files. The file names must match `front-matter*.html` and will be included in alphabetic order. The files are expected to be valid EPUB HTML files. _If only one front matter page is
303
307
  required, the default 'front-matter.html' file can be used instead._
@@ -885,7 +889,7 @@ endif::[]
885
889
  Copyright (C) 2014-2019 OpenDevise Inc. and the Asciidoctor Project.
886
890
  Free use of this software is granted under the terms of the MIT License.
887
891
 
888
- For the full text of the license, see the <<LICENSE#,LICENSE>> file.
892
+ For the full text of the license, see the link:LICENSE[] file.
889
893
  Refer to the <<NOTICE#,NOTICE>> file for information about third-party Open Source software in use.
890
894
 
891
895
  ////
@@ -24,14 +24,17 @@ An extension for Asciidoctor that converts AsciiDoc documents to EPUB3 and KF8/M
24
24
  rescue
25
25
  Dir['**/*']
26
26
  end
27
- s.files = files.grep %r/^(?:(?:data\/(?:fonts|images|styles)|lib)\/.+|Gemfile|Rakefile|(?:CHANGELOG|LICENSE|NOTICE|README)\.adoc|\.yardopts|#{s.name}\.gemspec)$/
27
+ s.files = files.grep %r/^(?:(?:data\/(?:fonts|images|styles)|lib)\/.+|Gemfile|Rakefile|LICENSE|(?:CHANGELOG|NOTICE|README)\.adoc|\.yardopts|#{s.name}\.gemspec)$/
28
28
  s.executables = %w(asciidoctor-epub3 adb-push-ebook)
29
29
  s.test_files = s.files.grep(/^(?:test|spec|feature)\/.*$/)
30
30
 
31
31
  s.require_paths = ['lib']
32
32
 
33
33
  s.add_development_dependency 'asciidoctor-diagram', '>= 1.5.0', '< 3.0.0'
34
+ s.add_development_dependency 'coderay', '~> 1.1.0'
35
+ s.add_development_dependency 'pygments.rb', '~> 1.2.0'
34
36
  s.add_development_dependency 'rake', '~> 13.0.0'
37
+ s.add_development_dependency 'rouge', '~> 3.0'
35
38
  s.add_development_dependency 'rspec', '~> 3.9.0'
36
39
  s.add_development_dependency 'rubocop', '~> 0.80.0'
37
40
  s.add_development_dependency 'rubocop-rspec', '~> 1.38.0'
@@ -28,8 +28,7 @@ body.gitden-reader {
28
28
  }*/
29
29
 
30
30
  /* Use tighter margins and smaller font (18px) on phones (Nexus 4 and smaller) */
31
- @media only screen and (max-device-width: 768px) and (max-device-height: 1280px),
32
- only screen and (max-device-width: 1280px) and (max-device-height: 768px) {
31
+ @media only screen and (max-device-width: 768px) and (max-device-height: 1280px), only screen and (max-device-width: 1280px) and (max-device-height: 768px) {
33
32
  body.gitden-reader,
34
33
  body.namo-epub-library {
35
34
  font-size: 112.5%;
@@ -38,7 +37,6 @@ only screen and (max-device-width: 1280px) and (max-device-height: 768px) {
38
37
  /*body.gitden-reader {
39
38
  margin: 0 5pt !important;
40
39
  }*/
41
-
42
40
  /*body.namo-epub-library > section.chapter {
43
41
  margin: 0 5pt;
44
42
  }*/
@@ -69,7 +67,6 @@ body code, body kbd, body pre, pre :not(code) {
69
67
  /*body {
70
68
  margin: 0 !important;
71
69
  }*/
72
-
73
70
  /* text-rendering is the only way to enable kerning in Kindle (and Calibre, though it seems to kern automatically) */
74
71
  /* personally, I think Kindle overdoes kerning, but we're running with it for now */
75
72
  /* text-rendering: optimizeLegibility kills certain Kindle eInk devices */
@@ -78,7 +75,6 @@ body code, body kbd, body pre, pre :not(code) {
78
75
  th, td, figcaption, caption {
79
76
  text-rendering: optimizeLegibility;
80
77
  }*/
81
-
82
78
  /* hack line height of subtitle using floats on Kindle */
83
79
  h1.chapter-title .subtitle {
84
80
  margin-top: -0.2em;
@@ -105,8 +101,7 @@ body code, body kbd, body pre, pre :not(code) {
105
101
  }
106
102
 
107
103
  /* Use darker font colors on Kindle Paperwhite */
108
- @media amzn-kf8 and (device-height: 1024px) and (device-width: 758px),
109
- amzn-kf8 and (device-height: 758px) and (device-width: 1024px) {
104
+ @media amzn-kf8 and (device-height: 1024px) and (device-width: 758px), amzn-kf8 and (device-height: 758px) and (device-width: 1024px) {
110
105
  body p,
111
106
  div.abstract > p,
112
107
  ul, ol, li, dl, dt, dd, footer,
@@ -131,7 +126,7 @@ body code, body kbd, body pre, pre :not(code) {
131
126
  color: #191918;
132
127
  border-bottom-color: #191918;
133
128
  }
134
-
129
+
135
130
  h1.chapter-title .subtitle,
136
131
  .chapter-header p.byline {
137
132
  color: #000000;
@@ -215,8 +215,8 @@ body a:link {
215
215
  body:first-of-type a:link {
216
216
  border-bottom: none;
217
217
  background-repeat: no-repeat;
218
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%, #666665 5%, #666665 95%, rgba(255,255,255,0) 100%);
219
- background-image: linear-gradient(to right, rgba(255,255,255,0) 0%, #666665 5%, #666665 95%, rgba(255,255,255,0) 100%);
218
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, #666665 5%, #666665 95%, rgba(255, 255, 255, 0) 100%);
219
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, #666665 5%, #666665 95%, rgba(255, 255, 255, 0) 100%);
220
220
  background-size: 100% 1px;
221
221
  background-position: 0 1.2em;
222
222
  }
@@ -905,7 +905,7 @@ pre {
905
905
  font-size: 0.85em;
906
906
  line-height: 1.4; /* matches what Kindle uses and can't go less */
907
907
  background-color: #F2F2F2;
908
- padding: 0.5rem 0.75rem;
908
+ padding: 0.6em 0.9em; /* this is supposed to be '0.5rem 0.75rem' but Sony Readers crash when see that (at least, PRS-350, PRS-505, PRS-T1) */
909
909
  /*
910
910
  border-top: 3px solid #DCDCDE;
911
911
  */
@@ -1028,8 +1028,8 @@ aside.note::before {
1028
1028
  }
1029
1029
 
1030
1030
  aside[class~="note"] > div[class~="content"] {
1031
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 42.5%, #FFC14F 45%, #FFC14F 55%, rgba(255,255,255,0) 57.5%);
1032
- background-image: linear-gradient(to right, rgba(255,255,255,0) 42.5%, #FFC14F 45%, #FFC14F 55%, rgba(255,255,255,0) 57.5%);
1031
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 42.5%, #FFC14F 45%, #FFC14F 55%, rgba(255, 255, 255, 0) 57.5%);
1032
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 42.5%, #FFC14F 45%, #FFC14F 55%, rgba(255, 255, 255, 0) 57.5%);
1033
1033
  }
1034
1034
 
1035
1035
  aside.tip::before {
@@ -1038,8 +1038,8 @@ aside.tip::before {
1038
1038
  }
1039
1039
 
1040
1040
  aside[class~="tip"] > div[class~="content"] {
1041
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 42.5%, #40403E 45%, #40403E 55%, rgba(255,255,255,0) 57.5%);
1042
- background-image: linear-gradient(to right, rgba(255,255,255,0) 42.5%, #40403E 45%, #40403E 55%, rgba(255,255,255,0) 57.5%);
1041
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 42.5%, #40403E 45%, #40403E 55%, rgba(255, 255, 255, 0) 57.5%);
1042
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 42.5%, #40403E 45%, #40403E 55%, rgba(255, 255, 255, 0) 57.5%);
1043
1043
  }
1044
1044
 
1045
1045
  aside.caution::before {
@@ -1048,8 +1048,8 @@ aside.caution::before {
1048
1048
  }
1049
1049
 
1050
1050
  aside[class~="caution"] > div[class~="content"] {
1051
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 42.5%, #7F7F7D 45%, #7F7F7D 55%, rgba(255,255,255,0) 57.5%);
1052
- background-image: linear-gradient(to right, rgba(255,255,255,0) 42.5%, #7F7F7D 45%, #7F7F7D 55%, rgba(255,255,255,0) 57.5%);
1051
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 42.5%, #7F7F7D 45%, #7F7F7D 55%, rgba(255, 255, 255, 0) 57.5%);
1052
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 42.5%, #7F7F7D 45%, #7F7F7D 55%, rgba(255, 255, 255, 0) 57.5%);
1053
1053
  }
1054
1054
 
1055
1055
  aside.warning::before {
@@ -1058,8 +1058,8 @@ aside.warning::before {
1058
1058
  }
1059
1059
 
1060
1060
  aside[class~="warning"] > div[class~="content"] {
1061
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 42.5%, #C83737 45%, #C83737 55%, rgba(255,255,255,0) 57.5%);
1062
- background-image: linear-gradient(to right, rgba(255,255,255,0) 42.5%, #C83737 45%, #C83737 55%, rgba(255,255,255,0) 57.5%);
1061
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 42.5%, #C83737 45%, #C83737 55%, rgba(255, 255, 255, 0) 57.5%);
1062
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 42.5%, #C83737 45%, #C83737 55%, rgba(255, 255, 255, 0) 57.5%);
1063
1063
  }
1064
1064
 
1065
1065
  aside.important::before {
@@ -1068,8 +1068,8 @@ aside.important::before {
1068
1068
  }
1069
1069
 
1070
1070
  aside[class~="important"] > div[class~="content"] {
1071
- background-image: -webkit-linear-gradient(left, rgba(255,255,255,0) 42.5%, #F2642A 45%, #F2642A 55%, rgba(255,255,255,0) 57.5%);
1072
- background-image: linear-gradient(to right, rgba(255,255,255,0) 42.5%, #F2642A 45%, #F2642A 55%, rgba(255,255,255,0) 57.5%);
1071
+ background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 42.5%, #F2642A 45%, #F2642A 55%, rgba(255, 255, 255, 0) 57.5%);
1072
+ background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 42.5%, #F2642A 45%, #F2642A 55%, rgba(255, 255, 255, 0) 57.5%);
1073
1073
  }
1074
1074
 
1075
1075
  aside.admonition > h2 {
@@ -1257,9 +1257,11 @@ nav#toc ol {
1257
1257
  table.table th, table.table td, div.verse .attribution {
1258
1258
  font-family: serif;
1259
1259
  }
1260
+
1260
1261
  h1, h2, h3, h4, h5, h6 {
1261
1262
  font-family: sans-serif;
1262
1263
  }
1264
+
1263
1265
  code, kbd, pre, i.conum {
1264
1266
  font-family: monospace;
1265
1267
  }
@@ -111,12 +111,35 @@ module Asciidoctor
111
111
  # See https://asciidoctor.org/docs/user-manual/#book-parts-and-chapters
112
112
  def get_chapter_name node
113
113
  if node.document.doctype != 'book'
114
- return Asciidoctor::Document === node ? node.attr('docname') : nil
114
+ return Asciidoctor::Document === node ? node.attr('docname') || node.id : nil
115
115
  end
116
116
  return (node.id || 'preamble') if node.context == :preamble && node.level == 0
117
117
  Asciidoctor::Section === node && node.level <= 1 ? node.id : nil
118
118
  end
119
119
 
120
+ def get_numbered_title node
121
+ doc_attrs = node.document.attributes
122
+ level = node.level
123
+ if node.caption
124
+ title = node.captioned_title
125
+ elsif node.respond_to?(:numbered) && node.numbered && level <= (doc_attrs['sectnumlevels'] || 3).to_i
126
+ if level < 2 && node.document.doctype == 'book'
127
+ if node.sectname == 'chapter'
128
+ title = %(#{(signifier = doc_attrs['chapter-signifier']) ? "#{signifier} " : ''}#{node.sectnum} #{node.title})
129
+ elsif node.sectname == 'part'
130
+ title = %(#{(signifier = doc_attrs['part-signifier']) ? "#{signifier} " : ''}#{node.sectnum nil, ':'} #{node.title})
131
+ else
132
+ title = %(#{node.sectnum} #{node.title})
133
+ end
134
+ else
135
+ title = %(#{node.sectnum} #{node.title})
136
+ end
137
+ else
138
+ title = node.title
139
+ end
140
+ title
141
+ end
142
+
120
143
  def convert_document node
121
144
  @format = node.attr('ebook-format').to_sym
122
145
 
@@ -182,6 +205,18 @@ module Asciidoctor
182
205
  @book.metadata.add_metadata 'subject', s
183
206
  end
184
207
 
208
+ if node.attr? 'series-name'
209
+ series_name = node.attr 'series-name'
210
+ series_volume = node.attr 'series-volume', 1
211
+ series_id = node.attr 'series-id'
212
+
213
+ series_meta = @book.metadata.add_metadata 'meta', series_name, id: 'pub-collection', group_position: series_volume
214
+ series_meta['property'] = 'belongs-to-collection'
215
+ series_meta.refine 'dcterms:identifier', series_id unless series_id.nil?
216
+ # Calibre only understands 'series'
217
+ series_meta.refine 'collection-type', 'series'
218
+ end
219
+
185
220
  add_cover_image node
186
221
  add_front_matter_page node
187
222
 
@@ -273,7 +308,7 @@ module Asciidoctor
273
308
  elsif node.title
274
309
  # HACK: until we get proper handling of title-only in CSS
275
310
  title = ''
276
- subtitle = node.title
311
+ subtitle = get_numbered_title node
277
312
  else
278
313
  title = nil
279
314
  subtitle = nil
@@ -321,6 +356,9 @@ module Asciidoctor
321
356
  </div>
322
357
  </header>) : ''
323
358
 
359
+ # TODO : support writing code highlighter CSS to a separate file
360
+ linkcss = false
361
+
324
362
  # NOTE kindlegen seems to mangle the <header> element, so we wrap its content in a div
325
363
  lines = [%(<!DOCTYPE html>
326
364
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="#{lang = node.document.attr 'lang', 'en'}" lang="#{lang}">
@@ -337,12 +375,17 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
337
375
  }
338
376
  document.body.setAttribute('class', reader.name.toLowerCase().replace(/ /g, '-'));
339
377
  });
340
- ]]></script>
341
- </head>
378
+ ]]></script>)]
379
+
380
+ if self.class.supports_highlighter_docinfo? && (syntax_hl = node.document.syntax_highlighter) && (syntax_hl.docinfo? :head)
381
+ lines << (syntax_hl.docinfo :head, node, linkcss: linkcss, self_closing_tag_slash: '/')
382
+ end
383
+
384
+ lines << %(</head>
342
385
  <body>
343
386
  <section class="chapter" title="#{doctitle_sanitized.gsub '"', '&quot;'}" epub:type="chapter" id="#{docid}">
344
387
  #{header}
345
- #{content})]
388
+ #{content})
346
389
 
347
390
  unless (fns = node.document.footnotes - @footnotes).empty?
348
391
  @footnotes += fns
@@ -361,8 +404,11 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
361
404
  </footer>'
362
405
  end
363
406
 
364
- lines << '</section>
365
- </body>
407
+ lines << '</section>'
408
+
409
+ lines << (syntax_hl.docinfo :footer, node.document, linkcss: linkcss, self_closing_tag_slash: '/') if syntax_hl && (syntax_hl.docinfo? :footer)
410
+
411
+ lines << '</body>
366
412
  </html>'
367
413
 
368
414
  chapter_item.add_content postprocess_xhtml lines * LF
@@ -380,7 +426,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
380
426
  hlevel = node.level
381
427
  epub_type_attr = node.special ? %( epub:type="#{node.sectname}") : ''
382
428
  div_classes = [%(sect#{node.level}), node.role].compact
383
- title = node.title
429
+ title = get_numbered_title node
384
430
  title_sanitized = xml_sanitize title
385
431
  %(<section class="#{div_classes * ' '}" title="#{title_sanitized}"#{epub_type_attr}>
386
432
  <h#{hlevel} id="#{node.id}">#{title}</h#{hlevel}>#{(content = node.content).empty? ? '' : %(
@@ -427,15 +473,16 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
427
473
  end
428
474
 
429
475
  def convert_paragraph node
476
+ id_attr = node.id ? %( id="#{node.id}") : ''
430
477
  role = node.role
431
478
  # stack-head is the alternative to the default, inline-head (where inline means "run-in")
432
479
  head_stop = node.attr 'head-stop', (role && (node.has_role? 'stack-head') ? nil : '.')
433
480
  head = node.title? ? %(<strong class="head">#{title = node.title}#{head_stop && title !~ TrailingPunctRx ? head_stop : ''}</strong> ) : ''
434
481
  if role
435
482
  node.set_option 'hardbreaks' if node.has_role? 'signature'
436
- %(<p class="#{role}">#{head}#{node.content}</p>)
483
+ %(<p#{id_attr} class="#{role}">#{head}#{node.content}</p>)
437
484
  else
438
- %(<p>#{head}#{node.content}</p>)
485
+ %(<p#{id_attr}>#{head}#{node.content}</p>)
439
486
  end
440
487
  end
441
488
 
@@ -498,13 +545,29 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
498
545
  end
499
546
 
500
547
  def convert_listing node
548
+ nowrap = (node.option? 'nowrap') || !(node.document.attr? 'prewrap')
549
+ if node.style == 'source'
550
+ lang = node.attr 'language'
551
+ if self.class.supports_highlighter_docinfo? && (syntax_hl = node.document.syntax_highlighter)
552
+ opts = syntax_hl.highlight? ? {
553
+ css_mode: ((doc_attrs = node.document.attributes)[%(#{syntax_hl.name}-css)] || :class).to_sym,
554
+ style: doc_attrs[%(#{syntax_hl.name}-style)],
555
+ } : {}
556
+ opts[:nowrap] = nowrap
557
+ else
558
+ pre_open = %(<pre class="highlight#{nowrap ? ' nowrap' : ''}"><code#{lang ? %( class="language-#{lang}" data-lang="#{lang}") : ''}>)
559
+ pre_close = '</code></pre>'
560
+ end
561
+ else
562
+ pre_open = %(<pre#{nowrap ? ' class="nowrap"' : ''}>)
563
+ pre_close = '</pre>'
564
+ syntax_hl = nil
565
+ end
501
566
  figure_classes = ['listing']
502
567
  figure_classes << 'coalesce' if node.option? 'unbreakable'
503
- pre_classes = node.style == 'source' ? ['source', %(language-#{node.attr 'language'})] : ['screen']
504
- title_div = node.title? ? %(<figcaption>#{node.captioned_title}</figcaption>
505
- ) : ''
506
- %(<figure class="#{figure_classes * ' '}">
507
- #{title_div}<pre class="#{pre_classes * ' '}"><code>#{node.content}</code></pre>
568
+ title_div = node.title? ? %(<figcaption>#{get_numbered_title node}</figcaption>) : ''
569
+ %(<figure class="#{figure_classes * ' '}">#{title_div}
570
+ #{syntax_hl ? (syntax_hl.format node, lang, opts) : pre_open + (node.content || '') + pre_close}
508
571
  </figure>)
509
572
  end
510
573
 
@@ -901,7 +964,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
901
964
  end
902
965
 
903
966
  id_attr = '' unless @xrefs_seen.add? refid
904
- text = (ref.xreftext node.attr('xrefstyle', nil, true))
967
+ text ||= (ref.xreftext node.attr('xrefstyle', nil, true))
905
968
  else
906
969
  logger.warn %(#{::File.basename doc.attr('docfile')}: invalid reference to unknown anchor: #{refid})
907
970
  end
@@ -1266,14 +1329,14 @@ body > svg {
1266
1329
  items.each do |item|
1267
1330
  #index = (state[:index] = (state.fetch :index, 0) + 1)
1268
1331
  if (chapter_name = get_chapter_name item).nil?
1269
- item_label = sanitize_xml item.title, :pcdata
1332
+ item_label = sanitize_xml get_numbered_title(item), :pcdata
1270
1333
  item_href = %(#{state[:content_doc_href]}##{item.id})
1271
1334
  else
1272
1335
  # NOTE we sanitize the chapter titles because we use formatting to control layout
1273
1336
  if item.context == :document
1274
1337
  item_label = sanitize_doctitle_xml item, :cdata
1275
1338
  else
1276
- item_label = sanitize_xml item.title, :cdata
1339
+ item_label = sanitize_xml get_numbered_title(item), :cdata
1277
1340
  end
1278
1341
  item_href = (state[:content_doc_href] = %(#{chapter_name}.xhtml))
1279
1342
  end
@@ -1316,13 +1379,13 @@ body > svg {
1316
1379
  index = (state[:index] = (state.fetch :index, 0) + 1)
1317
1380
  item_id = %(nav_#{index})
1318
1381
  if (chapter_name = get_chapter_name item).nil?
1319
- item_label = sanitize_xml item.title, :cdata
1382
+ item_label = sanitize_xml get_numbered_title(item), :cdata
1320
1383
  item_href = %(#{state[:content_doc_href]}##{item.id})
1321
1384
  else
1322
1385
  if item.context == :document
1323
1386
  item_label = sanitize_doctitle_xml item, :cdata
1324
1387
  else
1325
- item_label = sanitize_xml item.title, :cdata
1388
+ item_label = sanitize_xml get_numbered_title(item), :cdata
1326
1389
  end
1327
1390
  item_href = (state[:content_doc_href] = %(#{chapter_name}.xhtml))
1328
1391
  end
@@ -1498,6 +1561,14 @@ body > svg {
1498
1561
  def role_valid_class? role
1499
1562
  role.is_a? String
1500
1563
  end
1564
+
1565
+ class << self
1566
+ def supports_highlighter_docinfo?
1567
+ # Asciidoctor only got pluggable syntax highlighters since 2.0:
1568
+ # https://github.com/asciidoctor/asciidoctor/commit/23ddbaed6818025cbe74365fec7e8101f34eadca
1569
+ Asciidoctor::Document.method_defined? :syntax_highlighter
1570
+ end
1571
+ end
1501
1572
  end
1502
1573
 
1503
1574
  class DocumentIdGenerator
@@ -1561,13 +1632,16 @@ body > svg {
1561
1632
  Extensions.register do
1562
1633
  if (document = @document).backend == 'epub3'
1563
1634
  document.set_attribute 'listing-caption', 'Listing'
1564
- # pygments.rb hangs on JRuby for Windows, see https://github.com/asciidoctor/asciidoctor-epub3/issues/253
1565
- if !(::RUBY_ENGINE == 'jruby' && Gem.win_platform?) && (Gem.try_activate 'pygments.rb')
1566
- if document.set_attribute 'source-highlighter', 'pygments'
1567
- document.set_attribute 'pygments-css', 'style'
1568
- document.set_attribute 'pygments-style', 'bw'
1569
- end
1635
+
1636
+ # TODO: bw theme for CodeRay
1637
+ document.set_attribute 'pygments-style', 'bw' unless document.attr? 'pygments-style'
1638
+ document.set_attribute 'rouge-style', 'bw' unless document.attr? 'rouge-style'
1639
+ unless Converter.supports_highlighter_docinfo?
1640
+ document.set_attribute 'coderay-css', 'style'
1641
+ document.set_attribute 'pygments-css', 'style'
1642
+ document.set_attribute 'rouge-css', 'style'
1570
1643
  end
1644
+
1571
1645
  case (ebook_format = document.attributes['ebook-format'])
1572
1646
  when 'epub3', 'kf8'
1573
1647
  # all good
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Epub3
5
- VERSION = '1.5.0.alpha.14'
5
+ VERSION = '1.5.0.alpha.15'
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.14
4
+ version: 1.5.0.alpha.15
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-02-29 00:00:00.000000000 Z
12
+ date: 2020-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: asciidoctor-diagram
@@ -31,6 +31,34 @@ dependencies:
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 3.0.0
34
+ - !ruby/object:Gem::Dependency
35
+ name: coderay
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.0
48
+ - !ruby/object:Gem::Dependency
49
+ name: pygments.rb
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
34
62
  - !ruby/object:Gem::Dependency
35
63
  name: rake
36
64
  requirement: !ruby/object:Gem::Requirement
@@ -45,6 +73,20 @@ dependencies:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
75
  version: 13.0.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: rouge
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
48
90
  - !ruby/object:Gem::Dependency
49
91
  name: rspec
50
92
  requirement: !ruby/object:Gem::Requirement
@@ -132,10 +174,9 @@ executables:
132
174
  extensions: []
133
175
  extra_rdoc_files: []
134
176
  files:
135
- - ".yardopts"
136
177
  - CHANGELOG.adoc
137
178
  - Gemfile
138
- - LICENSE.adoc
179
+ - LICENSE
139
180
  - NOTICE.adoc
140
181
  - README.adoc
141
182
  - Rakefile
data/.yardopts DELETED
@@ -1,12 +0,0 @@
1
- --charset UTF-8
2
- --readme README.adoc
3
- --no-private
4
- --hide-api private
5
- --title "Asciidoctor EPUB3 API Docs"
6
- --output-dir apidoc
7
- --exclude /ext(?:\.rb$|/)
8
- lib/**/*.rb
9
- -
10
- CHANGELOG.adoc
11
- LICENSE.adoc
12
- NOTICE.adoc
@@ -1,25 +0,0 @@
1
- [[LICENSE]]
2
- = LICENSE
3
-
4
- .The MIT License
5
- ....
6
- Copyright (C) 2014-2019 OpenDevise Inc. and the Asciidoctor Project
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
- ....