asciidoctor-epub3 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.adoc +22 -0
  3. data/NOTICE.adoc +53 -0
  4. data/README.adoc +744 -0
  5. data/Rakefile +78 -0
  6. data/bin/adb-push-ebook +25 -0
  7. data/bin/asciidoctor-epub3 +15 -0
  8. data/data/fonts/assorted-icons.ttf +0 -0
  9. data/data/fonts/fontawesome-icons.ttf +0 -0
  10. data/data/fonts/mplus1mn-bold-ascii.ttf +0 -0
  11. data/data/fonts/mplus1mn-bolditalic-ascii.ttf +0 -0
  12. data/data/fonts/mplus1mn-italic-ascii.ttf +0 -0
  13. data/data/fonts/mplus1mn-regular-ascii-conums.ttf +0 -0
  14. data/data/fonts/mplus1p-bold-latin-cyrillic.ttf +0 -0
  15. data/data/fonts/mplus1p-bold-latin-ext.ttf +0 -0
  16. data/data/fonts/mplus1p-bold-latin.ttf +0 -0
  17. data/data/fonts/mplus1p-bold-multilingual.ttf +0 -0
  18. data/data/fonts/mplus1p-light-latin-cyrillic.ttf +0 -0
  19. data/data/fonts/mplus1p-light-latin-ext.ttf +0 -0
  20. data/data/fonts/mplus1p-light-latin.ttf +0 -0
  21. data/data/fonts/mplus1p-light-multilingual.ttf +0 -0
  22. data/data/fonts/mplus1p-regular-latin-cyrillic.ttf +0 -0
  23. data/data/fonts/mplus1p-regular-latin-ext.ttf +0 -0
  24. data/data/fonts/mplus1p-regular-latin.ttf +0 -0
  25. data/data/fonts/mplus1p-regular-multilingual.ttf +0 -0
  26. data/data/fonts/notoserif-bold-latin-cyrillic.ttf +0 -0
  27. data/data/fonts/notoserif-bold-latin-ext.ttf +0 -0
  28. data/data/fonts/notoserif-bold-latin.ttf +0 -0
  29. data/data/fonts/notoserif-bold-multilingual.ttf +0 -0
  30. data/data/fonts/notoserif-bolditalic-latin-cyrillic.ttf +0 -0
  31. data/data/fonts/notoserif-bolditalic-latin-ext.ttf +0 -0
  32. data/data/fonts/notoserif-bolditalic-latin.ttf +0 -0
  33. data/data/fonts/notoserif-bolditalic-multilingual.ttf +0 -0
  34. data/data/fonts/notoserif-italic-latin-cyrillic.ttf +0 -0
  35. data/data/fonts/notoserif-italic-latin-ext.ttf +0 -0
  36. data/data/fonts/notoserif-italic-latin.ttf +0 -0
  37. data/data/fonts/notoserif-italic-multilingual.ttf +0 -0
  38. data/data/fonts/notoserif-regular-latin-cyrillic.ttf +0 -0
  39. data/data/fonts/notoserif-regular-latin-ext.ttf +0 -0
  40. data/data/fonts/notoserif-regular-latin.ttf +0 -0
  41. data/data/fonts/notoserif-regular-multilingual.ttf +0 -0
  42. data/data/images/default-avatar.jpg +0 -0
  43. data/data/images/default-avatar.png +0 -0
  44. data/data/images/default-avatar.svg +67 -0
  45. data/data/images/default-cover-large.png +0 -0
  46. data/data/images/default-cover.png +0 -0
  47. data/data/images/default-cover.svg +53 -0
  48. data/data/images/default-headshot.jpg +0 -0
  49. data/data/images/default-headshot.png +0 -0
  50. data/data/samples/asciidoctor-epub3-readme.adoc +744 -0
  51. data/data/samples/asciidoctor-js-extension.adoc +46 -0
  52. data/data/samples/asciidoctor-js-introduction.adoc +91 -0
  53. data/data/samples/i18n.adoc +161 -0
  54. data/data/samples/images/asciidoctor-js-chrome-extension.png +0 -0
  55. data/data/samples/images/avatars/graphitefriction.png +0 -0
  56. data/data/samples/images/avatars/mogztter.png +0 -0
  57. data/data/samples/images/avatars/mojavelinux.png +0 -0
  58. data/data/samples/images/correct-text-justification.png +0 -0
  59. data/data/samples/images/incorrect-text-justification.png +0 -0
  60. data/data/samples/images/screenshots/chapter-title-day.png +0 -0
  61. data/data/samples/images/screenshots/chapter-title.png +0 -0
  62. data/data/samples/images/screenshots/figure-admonition.png +0 -0
  63. data/data/samples/images/screenshots/section-title-paragraph.png +0 -0
  64. data/data/samples/images/screenshots/sidebar.png +0 -0
  65. data/data/samples/images/screenshots/table.png +0 -0
  66. data/data/samples/images/screenshots/text.png +0 -0
  67. data/data/samples/sample-book.adoc +20 -0
  68. data/data/samples/sample-content.adoc +168 -0
  69. data/data/styles/color-palette.css +28 -0
  70. data/data/styles/epub3-css3-only.css +161 -0
  71. data/data/styles/epub3-fonts.css +94 -0
  72. data/data/styles/epub3.css +1293 -0
  73. data/lib/asciidoctor-epub3.rb +5 -0
  74. data/lib/asciidoctor-epub3/converter.rb +859 -0
  75. data/lib/asciidoctor-epub3/core_ext/string.rb +7 -0
  76. data/lib/asciidoctor-epub3/font_icon_map.rb +376 -0
  77. data/lib/asciidoctor-epub3/packager.rb +466 -0
  78. data/lib/asciidoctor-epub3/spine_item_processor.rb +72 -0
  79. data/lib/asciidoctor-epub3/version.rb +5 -0
  80. data/scripts/generate-font-subsets.pe +225 -0
  81. metadata +192 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6e1941b434f39af3cda0c2079d7697d2f6277786
4
+ data.tar.gz: 5e32f9533e5cb27a7dca30712fc0928e37c0730a
5
+ SHA512:
6
+ metadata.gz: 902f72d0b550593264cf3a06f472adcbd5602f9f04f3904a9061416572fce28d34b8dbb49c1157837d9572106abde3a8f62281177df3a36bd6d30b7b47cdecdf
7
+ data.tar.gz: ad8745fee5e4be8e7c0e5c7e6ed8743e0a32dc59af310d6181c483c7c857dff256d1f97dde82ce07349fd4c2a62e3a71ac9ac85f5555ce6976d7ce08df20f653
@@ -0,0 +1,22 @@
1
+ .The MIT License
2
+ ....
3
+ Copyright (C) 2014 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
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+ ....
@@ -0,0 +1,53 @@
1
+ = Asciidoctor EPUB3
2
+
3
+ Copyright (C) 2014 OpenDevise Inc. and the Asciidoctor Project.
4
+
5
+ Please visit the Asciidoctor project site for more information:
6
+
7
+ - http://asciidoctor.org
8
+
9
+ OpenDevise Inc. and the Asciidoctor Project licenses this product to you under the MIT License (the "License").
10
+ You may not use this product except in compliance with the License.
11
+ You may obtain a copy of the License at:
12
+
13
+ http://opensource.org/licenses/MIT
14
+
15
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and limitations under the License.
17
+
18
+ == Third-party licensed work
19
+
20
+ M+ OUTLINE FONTS (M+ TESTFLIGHT 058)::
21
+ The M+ OUTLINE FONTS are used for section titles, literal text and code annotation numbers and bundled in the EPUB3 archive.
22
+ These fonts are free software and are designed and maintained by Coji Morishita.
23
+ Unlimited permission is granted to use, copy, and distribute them, with or without modification, either commercially or noncommercially.
24
+ THESE FONTS ARE PROVIDED "AS IS" WITHOUT WARRANTY.
25
+
26
+ - http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
27
+
28
+ Noto Serif font::
29
+ Noto is font family developed by the Google Internationalization Team that aims to support all the world's languages.
30
+ The Noto Serif font is used for body copy and bundled in the EPUB3 archive.
31
+ The Noto fonts are licensed under the Apache 2.0 License.
32
+ You may obtain a copy of the license at:
33
+
34
+ http://www.apache.org/licenses/LICENSE-2.0
35
+
36
+ - https://code.google.com/p/noto/
37
+
38
+ Font Awesome icon font (v4.0.3)::
39
+ Font Awesome, the iconic font designed for Bootstrap by David Gandy, is used for the admonition icons and other icons in author's content and bundled in the EPUB3 archive.
40
+ Font Awesome is fully open source and GPL compatible.
41
+ The font is licensed under the SIL Open Font 1.1 License (OFL).
42
+ You may obtain a copy of the license at:
43
+
44
+ http://scripts.sil.org/OFL
45
+
46
+ - http://fontawesome.io
47
+
48
+ normalize.css (v3.0.1)::
49
+ A customized version of normalize.css is used to provide cross-reader consistency in the default styling of HTML elements.
50
+ The source of normalize.css is integrated into the default stylesheet that is bundled in the EPUB3 archive.
51
+ normalize.css is licensed under the MIT License.
52
+
53
+ - http://necolas.github.io/normalize.css
@@ -0,0 +1,744 @@
1
+ = Asciidoctor EPUB3: A _native_ EPUB3 converter for AsciiDoc
2
+ Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
3
+ :project-name: Asciidoctor EPUB3
4
+ :project-handle: asciidoctor-epub3
5
+ :project-uri: https://github.com/asciidoctor/{project-handle}
6
+ :project-repo-uri: {project-uri}
7
+ :project-issues-uri: {project-repo-uri}/issues
8
+ :rvm-uri: http://rvm.io
9
+ :asciidoctor-uri: http://asciidoctor.org
10
+ :idpf-uri: http://www.idpf.org/
11
+ :epub-uri: http://www.idpf.org/epub/30/spec/epub30-overview.html
12
+ :epubcheck-uri: https://github.com/idpf/epubcheck
13
+ ifdef::env-github[]
14
+ :base-uri: link:
15
+ endif::[]
16
+ ifndef::env-github[]
17
+ :base-uri: {project-repo-uri}/blob/master/
18
+ endif::[]
19
+ :notice-uri: {base-uri}NOTICE.adoc
20
+ :license-uri: {base-uri}LICENSE.adoc
21
+ :worklog-uri: {base-uri}WORKLOG.adoc
22
+ :imagesdir: data/samples/images
23
+ :experimental:
24
+
25
+ {project-name} is a set of Asciidoctor extensions for converting AsciiDoc documents directly to the EPUB3 and KF8/MOBI e-book formats.
26
+
27
+ == Introduction
28
+
29
+ {project-name} is not merely a converter from AsciiDoc to EPUB3 and KF8/MOBI, but rather a tool to help you create aesthetic, professional, _easy-to-read_ e-books.
30
+ Let's face it, many of the technical e-books out there--especially those produced from software documentation--are *_hideous_*.
31
+ The Asciidoctor project wants to disrupt the status quo.
32
+
33
+ ifdef::env-github[]
34
+ .An excerpt from an e-book produced by {project-name} shown in Day, Night and Sepia mode.
35
+ image::screenshots/text.png[]
36
+ endif::[]
37
+
38
+ === Project Mission
39
+
40
+ The {project-name} project aims to produce EPUB3 documents that meet the following objectives:
41
+
42
+ [itemized,subject-stop=.]
43
+ Fully Semantic::
44
+ Produce deeply semantic XHTML5 documents, including use of the recommended `epub:type` attribute.
45
+ Exceptional Readability::
46
+ Readers should be drawn into the text so that they read and absorb it, not scared away from it.
47
+ Maximize the readability of the text using carefully crafted styles, focusing on:
48
+ - Custom, readable fonts with strong UTF-8 character support
49
+ - Sufficient line spacing and margins
50
+ - Modular font size scale
51
+ - Subtle, pleasing colors with good contrast
52
+ - A responsive design that scales well from small to large screens
53
+ - Widowed and orphaned content avoided where possible
54
+ Complete & Accurate Metadata::
55
+ Fully populate the EPUB3 package metadata using information in the AsciiDoc source document.
56
+ Consistent Rendering::
57
+ Render consistently across a broad range of EPUB3 (and select EPUB2+) readers and respond to any size screen.
58
+ Polish, Polish & More Polish::
59
+ Add polish to the final product such as font-based icons and callout numbers.
60
+
61
+ We believe that the e-books produced by {project-name} are the _very best_ output you can expect to find in digital publishing today.
62
+ Of course, there's always room for improvement, so we'll continue to work with you to achieve and maintain this goal.
63
+
64
+ === Notable Features
65
+
66
+ * Direct AsciiDoc to EPUB3 conversion
67
+ * Direct AsciiDoc to KF8/MOBI conversion
68
+ * Highly-aesthetic and readable styles with optimized text legibility
69
+ * EPUB3 metadata, manifest and spine (assembled by Gepub)
70
+ * Document metadata (title, authors, subject, keywords, etc.)
71
+ * Internal cross reference links
72
+ * Syntax highlighting with CodeRay or Pygments (must use inline styles)
73
+ * Unicode callout numbers
74
+ * Page breaks avoided in block content (so much as it's supported by the reader)
75
+ * Orphan section titles avoided (so much as it's supported by the reader)
76
+ * Table border settings honored
77
+ * Support for SVG images in the content
78
+
79
+ === Project Status
80
+
81
+ CAUTION: {project-name} is currently _alpha_ software.
82
+ Use accordingly.
83
+ Although the bulk of AsciiDoc content is rendered, there's still work needed to fill in gaps where rendering is incomplete or unstyled.
84
+ Once it's battle tested, the project will be moved into the Asciidoctor organization on GitHub.
85
+
86
+ NOTE: {project-name} only produces variable layout (i.e., reflowable) EPUB3 documents since this layout is best suited for the types of documents typically written in AsciiDoc.
87
+ We may explore the use of fixed layout documents in the future if the need arises.
88
+
89
+ === Planned Features and Work In Progress
90
+
91
+ See {worklog-uri}[WORKLOG.adoc].
92
+
93
+ == Converter Workflow
94
+
95
+ {project-name} takes a single, logical AsciiDoc document as input and converts it to an EPUB3 publication archive (often described as a “website in a box”).
96
+ Using the EPUB3 publication as the “digital master”, {project-name} can then produce a KF8/MOBI, the file format required by Amazon Kindle.
97
+ The conversion to KF8/MOBI is performed by sending the EPUB3 through http://www.amazon.com/gp/feature.html?docId=1000765211[KindleGen].
98
+
99
+ An EPUB3 archive is typically structured with the contents of each “chapter” in a separate XHTML file.
100
+ The converter must therefore “chunk” the source document into multiple XHTML files to put in the EPUB3 archive.
101
+ Other converters tend to handle this task by automatically slicing up the XHTML output at predetermined heading levels.
102
+ Asciidoctor takes a different approach.
103
+
104
+ === Declaring the Spine
105
+
106
+ Asciidoctor relies on top-level include directives (i.e., include directives in the master document) to indicate where the chapter splits should occur.
107
+ In other words, you must be explicit.
108
+ Asciidoctor will not try to guess.
109
+ If your AsciiDoc document is not structured in this way, you'll need to change it to use the {project-name} converter properly.
110
+
111
+ You can think of the master document as the spine of the book and the include directives the individual items being bound together.
112
+ The target of each include directive in the master document is parsed and rendered as a separate AsciiDoc document, with certain options and attributes being passed down from the master to ensure consistent behavior.
113
+ Each resulting XHTML document is then added to the EPUB3 archive as a chapter document and the master document becomes the navigation file (i.e, the table of contents).
114
+
115
+ If the master document does not contain any include directives, then the converter treats the document as the sole chapter in the EPUB3 archive and automatically produces a navigation file that references it.
116
+
117
+ Eventually, we envision introducing a dedicated block macro to represent a spine item so that we don't overload the meaning of the include directive.
118
+ However, for the time being, the include directive will suit this purpose.
119
+
120
+ == Prerequisites
121
+
122
+ All that's needed to use {project-name} is Ruby 1.9.3 or better and a few RubyGems, which we'll explain how to install in the next section.
123
+
124
+ To check if you have Ruby available, use the `ruby` command to query the version installed:
125
+
126
+ $ ruby --version
127
+
128
+ If you're using {rvm-uri}[RVM], we recommend creating a new gemset to work with {project-name}:
129
+
130
+ $ rvm use @asciidoctor-epub3 --create
131
+
132
+ We like RVM because it keeps the dependencies required by various projects isolated ;)
133
+
134
+ == Getting Started
135
+
136
+ {project-name} isn't yet published as a RubyGem itself, so you'll need to get the source code.
137
+
138
+ === Retrieve the project
139
+
140
+ You can retrieve {project-name} in one of two ways:
141
+
142
+ . Clone the git repository
143
+ . Download a zip archive of the repository
144
+
145
+ ==== Option 1: Fetch Using `git clone`
146
+
147
+ If you want to clone the git repository, simply copy the {project-repo-uri}[GitHub repository URL] and pass it to the `git clone` command:
148
+
149
+ $ git clone https://github.com/asciidoctor/asciidoctor-epub3
150
+
151
+ Next, change to the project directory:
152
+
153
+ $ cd asciidoctor-epub3
154
+
155
+ ==== Option 2: Download the Archive
156
+
157
+ If you want to download a zip archive, click on the btn:[icon:cloud-download[\] Download Zip] button on the right-hand side of the repository page on GitHub.
158
+ Once the download finishes, extract the archive, open a console and change to that directory.
159
+
160
+ We'll now leverage the project configuration to install the necessary dependencies.
161
+
162
+ === Install the Dependencies
163
+
164
+ The dependencies needed to use {project-name} are defined in the [file]_Gemfile_ at the root of the project.
165
+ We can use Bundler to install the dependencies for us.
166
+
167
+ To check if you have Bundler available, use the `bundle` command to query the version installed:
168
+
169
+ $ bundle --version
170
+
171
+ If it's not installed, use the `gem` command to install it.
172
+
173
+ $ gem install bundle
174
+
175
+ Then use the `bundle` command to install the project dependencies:
176
+
177
+ $ bundle install
178
+
179
+ === Build and Install the Gem
180
+
181
+ Now that the dependencies are installed, you can build and install the Gem.
182
+
183
+ Use the Rake build tool to build the Gem:
184
+
185
+ $ rake build
186
+
187
+ The build will report that it built the Gem into the [path]_pkg_ directory.
188
+
189
+ Finally, install the Gem.
190
+
191
+ $ gem install pkg/asciidoctor-epub3-1.0.0.dev.gem
192
+
193
+ You're now ready to use {project-name}!
194
+ Let's get an AsciiDoc document ready to convert to EPUB3.
195
+
196
+ === Prepare an AsciiDoc Document
197
+
198
+ If you don't already have an AsciiDoc document, you can use the [file]_sample-book.adoc_ file and its chapters found in the [path]_data/samples_ directory of this project.
199
+
200
+ .Master file named sample-book.adoc
201
+ ```asciidoc
202
+ = Asciidoctor EPUB3: Sample Book
203
+ Author Name
204
+ v1.0, 2014-04-15
205
+ :doctype: book
206
+ :producer: Asciidoctor
207
+ :keywords: Asciidoctor, samples, e-book, EPUB3, KF8, MOBI, Asciidoctor.js
208
+ :copyright: CC-BY-SA 3.0
209
+ :imagesdir: images
210
+
211
+ \include::asciidoctor-epub3-readme.adoc[]
212
+
213
+ \include::sample-content.adoc[]
214
+
215
+ \include::asciidoctor-js-introduction.adoc[]
216
+
217
+ \include::asciidoctor-js-extension.adoc[]
218
+ ```
219
+
220
+ === EPUB-related AsciiDoc Attributes
221
+
222
+ The metadata in the generated EPUB3 file is populated from attributes in the AsciiDoc document.
223
+ The names of the attributes and the metadata elements to which they map are documented in this section.
224
+
225
+ The term [term]_package metadata_ in Table 1 is in reference to the http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-metadata-elem[<metadata> element] in the EPUB3 package document (e.g., [file]_package.opf_).
226
+ The `dc` namespace prefix is in reference to the http://dublincore.org/documents/2004/12/20/dces[Dublin Core Metadata Element Set].
227
+
228
+ .AsciiDoc attributes that control the EPUB3 metadata (i.e., package.opf)
229
+ [cols="1m,3"]
230
+ |===
231
+ |Name |Description
232
+
233
+ |id
234
+ |Populates the *required* unique identifier (`<dc:identifier>`) in the package metadata.
235
+ An id will be generated automatically from the doctitle if not specified.
236
+ The recommended practice is to identify the document by means of a string or number conforming to a formal identification system.
237
+
238
+ |lang
239
+ |Populates the content language / locale (`<dc:language>`) in the package metadata.
240
+
241
+ |scripts
242
+ |Controls the font subsets that are selected based on the specified scripts (e.g., alphabets). (values: *latin*, latin-ext, latin-cyrillic or multilingual)
243
+
244
+ |revdate
245
+ |Populates the publication date (`<dc:date>`) in the package metadata.
246
+ The date should be specified in a parsable format, such as `2014-01-01`.
247
+
248
+ |doctitle
249
+ |Populates the title (`<dc:title>`) in the package metadata.
250
+ The title is added to the metadata in plain text format.
251
+
252
+ |author
253
+ |Populates the contributors (`<dc:contributor>`) in the package metadata.
254
+ The authors in each chapter document are aggregated together with the authors in the master file.
255
+
256
+ |username
257
+ |Used to resolve an avatar for the author that is displayed in the header of a chapter.
258
+ The avatar image should be located at the path _$${imagesdir}/avatars/{username}.png$$_, where
259
+ `{username}` is the value of this attribute.
260
+
261
+ |producer
262
+ |Populates the publisher (`<dc:publisher>`) in the package metadata.
263
+
264
+ |creator
265
+ |Populates the creator (`<dc:creator>`) in the package metadata.
266
+ If the creator is not specified, the value of the producer attribute is used.
267
+
268
+ |description
269
+ |Populates the description (`<dc:description>`) in the package metadata.
270
+
271
+ |keywords
272
+ |Populates the subjects (i.e., `<dc:subject>`) in the package metadata.
273
+ The keywords should be represented as comma-separated values (CSV).
274
+
275
+ |front-cover-image
276
+ |Populates the front cover image and the image on the cover page (EPUB3 only) in the package metadata.
277
+ The image is also added to the e-book archive.
278
+ May be specified as a path or inline image macro.
279
+ Using the inline image macro is preferred as it allows the height and width to be specified.
280
+
281
+ |copyright
282
+ |Populates the rights statement (`<dc:rights>`) in the package metadata.
283
+
284
+ |source
285
+ |Populates the source reference (`<dc:source>`) in the package metadata.
286
+ The recommended practice is to identify the referenced resource by means of a string or number conforming to a formal identification system.
287
+
288
+ |epub-properties
289
+ |An optional override of the properties attribute for this document's item in the manifest.
290
+ _Only applies to a chapter document._
291
+
292
+ |doctype
293
+ |Effectively ignored.
294
+ The master document is assumed to be a book and each chapter an article.
295
+ |===
296
+
297
+ When using the EPUB3 converter, the `ebook-format` attribute resolves to the name of the e-book format being generated (epub3 or kf8) and the corresponding attribute `ebook-format-<name>` is defined, where `<name>` is `epub3` or `kf8`.
298
+ You can use these attributes in a preprocessor directive if you only want to show certain content to readers using a particular device.
299
+ For instance, if you want to display a message to readers on Kindle, you can use:
300
+
301
+ ----
302
+ \ifdef::ebook-format-kf8[Hello Kindle reader!]
303
+ ----
304
+
305
+ With that out of the way, it's time to convert the AsciiDoc document directly to EPUB3.
306
+
307
+ == Performing the Conversion
308
+
309
+ You can convert AsciiDoc documents to EPUB3 and KF8/MOBI from the commandline using the `asciidoctor-epub3` script provided with the {project-name} project.
310
+
311
+ === Convert AsciiDoc to EPUB3
312
+
313
+ Converting an AsciiDoc document to EPUB3 is as simple as passing your document to the `asciidoctor-epub3` command.
314
+ This command should be available on your PATH if you installed the `asciidoctor-epub3` gem.
315
+ Otherwise, you can find the command in the [path]_bin_ folder of the project.
316
+ We also recommend specifying an output directory using the `-D` option flag.
317
+
318
+ $ asciidoctor-epub3 -D output data/samples/sample-book.adoc
319
+
320
+ When the script completes, you'll see the file [file]_sample-book.epub_ appear in the [path]_output_ directory.
321
+ Open that file with an EPUB3 reader to view the result.
322
+
323
+ Below are several screenshots of this sample book as it appears on an Android phone.
324
+
325
+ .An example of a chapter title and abstract shown side-by-side in Day and Night mode
326
+ image::screenshots/chapter-title.png[]
327
+
328
+ .An example of a section title followed by paragraph text separated by a literal block
329
+ image::screenshots/section-title-paragraph.png[]
330
+
331
+ .An example of a figure and an admonition
332
+ image::screenshots/figure-admonition.png[]
333
+
334
+ .An example of a sidebar
335
+ image::screenshots/sidebar.png[]
336
+
337
+ .An example of a table
338
+ image::screenshots/table.png[]
339
+
340
+ NOTE: The `asciidoctor-epub3` command is a temporary solution for invoking the {project-name} converter.
341
+ We plan to remove this script once we have completed proper integration with the `asciidoctor` command.
342
+
343
+ TIP: As another example, point `asciidoctor-epub3` at the https://github.com/opendevise/github-guides-asciidoc[GitHub Guides] that we've ported to AsciiDoc, then compare the output to the real https://guides.github.com[GitHub Guides].
344
+
345
+ === Validate the EPUB3 Archive
346
+
347
+ Next, let's validate the EPUB3 archive to ensure it built correctly.
348
+
349
+ .EPUB3 with validation
350
+ $ asciidoctor-epub3 -D output -a ebook-validate data/samples/sample-book.adoc
351
+
352
+ .Validation success
353
+ ----
354
+ Epubcheck Version 3.0.1
355
+
356
+ Validating against EPUB version 3.0
357
+ No errors or warnings detected.
358
+ ----
359
+
360
+ If the EPUB3 archive contains any errors, they will be output in your terminal.
361
+
362
+ .EPUB Standard & Validator
363
+ ****
364
+ The electronic publication (EPUB) standard is developed by the {idpf-uri}[International Digital Publishing Forum (IDPF)].
365
+ {epub-uri}[EPUB 3.0], released in October 2011, is the latest version of this standard.
366
+
367
+ An EPUB3 archive contains:
368
+
369
+ * a package document (metadata, file manifest, spine)
370
+ * a navigation document (table of contents)
371
+ * one or more content documents
372
+ * assets (images, fonts, stylesheets, etc.)
373
+
374
+ The IDPF also supports {epubcheck-uri}[EpubCheck].
375
+ EpubCheck parses and validates the file against the EPUB schema.
376
+ ****
377
+
378
+ If you want to browse the contents of the EPUB3 file that is generated, or preview the XHTML files in a regular web browser, add the `-a ebook-extract` flag to the `asciidoctor-epub3` command.
379
+ The EPUB3 file will be extracted to a directory adjacent to the generated file, but without the file extension.
380
+
381
+ $ asciidoctor-epub3 -D output -a ebook-extract data/samples/sample-book.adoc
382
+
383
+ In this example, the contents of the EPUB3 will be extracted to the [path]_output/sample-book_ directory.
384
+
385
+ === Convert AsciiDoc to KF8/MOBI
386
+
387
+ Creating a KF8/MOBI archive directly from an AsciiDoc document is done with the same generation script (`asciidoctor-epub3`).
388
+ You just need to specify the format (`-a ebook-format`) as `kf8`.
389
+
390
+ $ asciidoctor-epub3 -D output -a ebook-format=kf8 data/samples/sample-book.adoc
391
+
392
+ When the script completes, you'll see the file [file]_sample-book.mobi_ appear in the [path]_output_ directory.
393
+
394
+ KindleGen does mandatory validation so you don't need to run the `validate` command after converting to KF8/MOBI.
395
+
396
+ .What is KF8?
397
+ ****
398
+ Kindle Format 8 (KF8) is Amazon's next generation file format offering a wide range of new features and enhancements--including HTML5 and CSS3 support--that publishers can use to create a broad range of books.
399
+ The format is close enough to EPUB3 that it's safe to think of it simply as an EPUB3 implementation under most circumstances.
400
+ You can read more about the format on the http://www.amazon.com/gp/feature.html?docId=1000729511[Kindle Format 8 page].
401
+
402
+ Amazon continues to use the _.mobi_ file extension for KF8 archives, despite the fact that they've switched from the Mobipocket format to the EPUB3-like KF8 format.
403
+ That's why we refer to the format in this project as KF8/MOBI.
404
+ ****
405
+
406
+ === Command Arguments
407
+
408
+ *-h, --help* ::
409
+ Show the usage message
410
+
411
+ *-D, --destination-dir* ::
412
+ Writes files to specified directory (defaults to the current directory)
413
+
414
+ *-a ebook-extract* ::
415
+ Extracts the EPUB3 to a folder in the destination directory after the file is generated
416
+
417
+ *-a ebook-format=<format>* ::
418
+ Specifies the e-book format to generate (epub3 or kf8, default: epub3)
419
+
420
+ *-a ebook-validate* ::
421
+ Runs Epubcheck 3.0.1 to validate output file against the EPUB3 specification
422
+
423
+ *-v, --version* ::
424
+ Display the program version
425
+
426
+ === EPUB3 Archive Structure
427
+
428
+ Here's a sample manifest of files found in an EPUB3 document produced by Asciidoctor EPUB3.
429
+
430
+ ....
431
+ META-INF/
432
+ container.xml
433
+ OEBPS/
434
+ fonts/
435
+ font-awesome.ttf
436
+ font-icons.ttf
437
+ mplus-1mn-latin-bold.ttf
438
+ mplus-1mn-latin-light.ttf
439
+ mplus-1mn-latin-medium.ttf
440
+ mplus-1mn-latin-regular.ttf
441
+ mplus-1p-latin-bold.ttf
442
+ mplus-1p-latin-light.ttf
443
+ mplus-1p-latin-regular.ttf
444
+ noto-serif-bold-italic.ttf
445
+ noto-serif-bold.ttf
446
+ noto-serif-italic.ttf
447
+ noto-serif-regular.ttf
448
+ images/
449
+ avatars/
450
+ default.png
451
+ figure-01.png
452
+ figure-02.png
453
+ styles/
454
+ epub3-css3-only.css
455
+ epub3.css
456
+ chapter-01.xhtml
457
+ chapter-02.xhtml
458
+ ...
459
+ cover.xhtml
460
+ nav.xhtml
461
+ package.opf
462
+ toc.ncx
463
+ mimetype
464
+ ....
465
+
466
+ == Working with Images
467
+
468
+ Images that your AsciiDoc document references should be saved in the directory defined in the `imagesdir` attribute, which defaults to the directory of the document.
469
+ {project-name} will discover all local image references and insert the images into the EPUB3 archive at the same relative path.
470
+
471
+ The sample book contains placeholder images for an author avatar and a book cover.
472
+
473
+ // TODO explain the avatar and book cover images
474
+
475
+ === Changing the Cover Image
476
+
477
+ E-book readers have different image resolution and file size limits regarding a book's cover.
478
+ Kindle covers tend to be 1050x1600 (16:9 resolution), which is the size of the sample cover provided with {project-name}.
479
+ To ensure your cover displays correctly, you'll want to review the documentation or publisher guidelines for the application you're targeting.
480
+
481
+ WARNING: We've found that if the book cover is more than 1600px on any side, Aldiko will not render it and may even crash.
482
+
483
+ Feel free to use the SVG of the sample cover in the [path]_data/images_ folder as a template for creating your own cover.
484
+ Once your image is ready, you can replace the placeholder cover image by defining the `front-cover-image` attribute in the header of the master document.
485
+
486
+ ----
487
+ :front-cover-image: image:cover.png[width=1050,height=1600]
488
+ ----
489
+
490
+ The image is resolved relative to the directory specified in the `imagesdir` attribute, which defaults to the document directory.
491
+ The image can be in any format, though we recommend using PNG or JPG as they are the most portable formats.
492
+
493
+ IMPORTANT: You should always specify the dimensions of the cover image.
494
+ This ensures the viewer will preserve the aspect ratio if it needs to be scaled to fit the screen.
495
+ If you don't specify a width and height, then the dimensions are assumed to be 1050x1600.
496
+
497
+ == About the Theme
498
+
499
+ EPUB3 and KF8/MOBI files are styled using CSS3.
500
+ However, each e-book reader honors a reduced set of CSS3 styles, and the styles they allow and how they implement them are rarely documented.
501
+ All we've got to say is _thank goodness for CSS hacks, media queries and years of CSS experience!_
502
+
503
+ The theme provided with {project-name} has been crafted to display EPUB3 and KF8/MOBI files as consistently as possible across the most common EPUB3 reader applications and to degrade gracefully in select EPUB2 readers.
504
+ The theme maintains readability regardless of the e-book reader's background mode (i.e., day, night or sepia) or the display device's pixel density and screen resolution.
505
+
506
+ The theme's CSS files are located in the [path]_data/style_ directory.
507
+
508
+ IMPORTANT: {project-name} only provides one theme, and, at this time, you can not replace it with a custom theme using the `stylesheet` attribute.
509
+
510
+ === Fonts
511
+
512
+ {project-name} embeds a set of fonts and font icons.
513
+ The theme's fonts are located in the [path]_data/fonts_ directory.
514
+
515
+ The M+ Outline fonts are used for titles, headings, literal (monospace) text, and annotation numbers.
516
+ The body text uses Noto Serif.
517
+ Admonition icons and the end-of-chapter mark are from the Font Awesome icon font.
518
+ Refer to the {notice-uri}[NOTICE.adoc] file for further information about the fonts.
519
+
520
+ // TODO document command to generate the M+ 1p latin fonts
521
+
522
+ === The text justification hack
523
+
524
+ Many of the EPUB3 readers use the http://webkit.org[WebKit browser engine] to render the content and apply the CSS formatting and styles.
525
+ Generally speaking, WebKit is a great engine that brings a lot of consistency and power to the e-book reader landscape.
526
+ It also brings along the same set of bugs.
527
+
528
+ One of the bugs in WebKit causes rich text to be justified incorrectly.
529
+ In particular, when the value of the `text-align` property is `justify`, WebKit drops the space between formatted text (bold, italic, hyperlink, etc) and non-formatted text, causing the words to be unevenly spaced across the line.
530
+ You can see an example of this problem in the screenshot below.
531
+
532
+ .WebKit justifying rich text incorrectly
533
+ image::incorrect-text-justification.png[]
534
+
535
+ It's not terrible, but just enough to disrupt a reader's flow.
536
+ Here's how we expect the text to look:
537
+
538
+ .WebKit justifying rich text correctly after the “word joiner hack” is applied
539
+ image::correct-text-justification.png[]
540
+
541
+ After some time in the tech lab and some dumb luck, we found a way to trick WebKit into justifying the text correctly!
542
+ We call it the “word joiner hack”.
543
+
544
+ Here's the HTML source of the first sentence from the screenshots:
545
+
546
+ ```xml
547
+ <strong><a href="...">Fork</a>⁠ the repository</stong> <span>and clone it locally.</span>
548
+ ```
549
+
550
+ WebKit treats the space following an inline element as insignificant and thus fails to account for it when justifying the text.
551
+
552
+ At first glance, you might think to add a normal space character before the closing tag of the inline element (e.g., `<a href="...">Fork </a>`).
553
+ However, that would cause any underline beneath links to extend past the end of the word.
554
+
555
+ At second glance, you might think to add a zero-width space character immediately following the element (e.g., `<a href="...">Fork</a>&#x200b;`).
556
+ However, that's problematic if the next character is a period or other punctuation because it introduces a wrap opportunity where there shouldn't be one.
557
+
558
+ Reflecting on the problem of the zero-width space brings us to either the http://www.fileformat.info/info/unicode/char/FEFF/index.htm[zero-width no-break space] character (e.g., `<a href="...">Fork</a>&#xfeff`) or the http://www.fileformat.info/info/unicode/char/2060/index.htm[word joiner] character (e.g., `<a href="...">Fork</a>&#x2060;`).
559
+ Like the zero-width space, these characters occupy no space.
560
+ However, instead of introducing a wrap opportunity, they prevent one.
561
+
562
+ But here's the clincher.
563
+ If the character following a zero-width non-break space or a word joiner is a normal space (e.g., `<a href="...">Fork</a>&#xfeff; the`), then it behaves just like a regular space.
564
+ We've covered all the scenarios!
565
+ Hey WebKit, you've been Unicode punked!
566
+
567
+ *UPDATE:* The zero-width no-break space was deprecated in favor of the word joiner.
568
+ However, as we've discovered, font support for the word joiner is absymal, whereas the zero-width no-break space is supported everywhere we've checked.
569
+ Therefore, we've decided to go with the zero-width no-break space to avoid nasty rectangle outlines from font bombing your content.
570
+
571
+ _By adding the +++<del>word joiner</del>+++ zero-width no-break space character immediately after any inline element, we can trick WebKit into justifying the text properly, as shown in the second screenshot above._
572
+
573
+ NOTE: You won't see `&#xfeff;` anywhere in the HTML source.
574
+ That's because we use the actual Unicode character so that any regular expressions being applied to the text still work as expected.
575
+
576
+ Although the fix may seem minor enhancement, it plays an important role in reaching one of the core objectives of this converter: to make the text in the EPUB3 as readable as possible.
577
+
578
+ === Device-specific Styles
579
+
580
+ For readers that support JavaScript, {project-name} adds a CSS class to the body element of each chapter that corresponds to the name of the reader as reported by the http://www.idpf.org/epub/301/spec/epub-contentdocs.html#app-epubReadingSystem[epubReadingSystem] JavaScript object.
581
+ This enhancement allows you to use styles targeted specifically at that reader.
582
+
583
+ Below you can find the readers that are known to support this feature and the CSS class name that gets added to the body element.
584
+
585
+ ,===
586
+ Reader,body class name
587
+
588
+ Gitden,gitden-reader
589
+ Namo PubTreeViewer,namo-epub-library
590
+ Readium,epub-js-viewer
591
+ iBooks,ibooks
592
+ Google Books,gb-reader-container (div)
593
+ ,===
594
+
595
+ == Pushing to Android
596
+
597
+ While it's certainly possible to view the EPUB3 on your desktop/laptop, you'll probably want to test it where it's most likely going to be read--on a reading device such as a smartphone or a tablet.
598
+ Assuming you have an Android device available, transferring the EPUB3 to the device is easy once you get a bit of setup out of the way.
599
+
600
+ You transfer files from your computer to an Android phone over a USB connection using a command from the Android SDK Tools called `adb`.
601
+ Follow these steps to get it setup:
602
+
603
+ . Download the Android SDK Tools zip from the table labeled *SDK Tools Only* on the http://developer.android.com/sdk/index.html[Get the Android SDK] page
604
+ . Extract the archive
605
+ . Locate the path to the `adb` command (Hint: Look in the platform-tools folder)
606
+ . Set the environment variable named ADB to the path of the `adb` command
607
+
608
+ $ export ADB=~/apps/android-sdk/platform-tools/adb
609
+
610
+ Now you can use the `adb-push-ebook` script provided by {project-name} to push the EPUB3 and KF8/MOBI files to your Android device.
611
+
612
+ .Publish both EPUB3 and KF8 files to Android device
613
+ $ adb-push-ebook output/sample-book
614
+
615
+ IMPORTANT: Don't include the file extension since the script will check for both the .epub and .mobi files.
616
+
617
+ The `adb-push-ebook` script copies the files to the following locations on the device:
618
+
619
+ ,===
620
+ File type,Destination on Android device
621
+
622
+ *.epub,/sdcard/
623
+ *.mobi,/sdcard/Android/data/com.amazon.kindle/files/
624
+ ,===
625
+
626
+ Amazon Kindle should immediately detect the new file and display it in your “On Device” library.
627
+ You'll have to manually import the EPUB3 into your reader application of choice.
628
+
629
+ == E-book Reader Recommendations and Quirks
630
+
631
+ EPUB3 readers will provide the best reading experience when viewing the book generated by {project-name}.
632
+ Here's a list of some of the readers we know to have good EPUB3 support and the systems on which they run:
633
+
634
+ * http://www.amazon.com/gp/feature.html?docId=1000493771[Amazon Kindle] (most platforms)
635
+ * http://gitden.com/gitdenreader[Gitden] (Android and iOS)
636
+ * http://www.apple.com/ibooks[iBooks] (iOS, OSX)
637
+ * https://chrome.google.com/webstore/detail/readium/fepbnnnkkadjhjahcafoaglimekefifl?hl=en-US[Readium] (Chrome)
638
+ * http://www.kobo.com/apps[Kobo] (Android, iOS, OSX and Windows)
639
+ * http://www.namo.com/site/namo/menu/5074.do[Namo PubTreeViewer] (Android, iOS and Windows)
640
+ * http://calibre-ebook.com[Calibre ebook-viewer] (Linux, OSX, Windows)
641
+
642
+ IMPORTANT: To get the full experience, ensure that the reader is configured to use the publisher's styles.
643
+ Different readers word this setting in different ways.
644
+ Look for the option screen that allows you to set the fonts and font colors and disable it.
645
+ With publisher's styles active, you'll still be able to adjust the relative size of the fonts and margins and toggle between day, night and sepia mode.
646
+
647
+ When the book is viewed in EPUB2 readers and Kindle apps/devices which have reached their end-of-life (EOL), the e-book relies on the strong semantics of the HTML and some fallback styles to render properly.
648
+ EPUB2 readers, such as Aldiko, don't understand CSS3 styles and therefore miss out on some of subtleties in the formatting.
649
+
650
+ As mentioned in the <<_about_the_theme,theme section>>, the stylesheet attempts to provide as consistent a reading experience as possible in the common EPUB3 readers, despite the different CSS implementation rules and limitations unique to each e-book application.
651
+ Most of these obstacles were addressed using media queries or explicit classes.
652
+ Some we haven't conquered.
653
+ Yet.
654
+
655
+ The <<_kindle_quirks,Kindle quirks list>> shows you just a few of the constraints we encountered.
656
+ To see all of the workarounds and why we chose certain style options, check out the code and comments in the [file]_epub3.css_ and [file]_epub3-css-only.css_ files.
657
+
658
+ // TODO add http://www.namo.com/site/namo/menu/5074.do[Namo PubTreeViewer] (iOS, Android & Windows) and http://www.kobo.com/apps[Kobo] (iOS, Android, OSX & Windows)
659
+
660
+ [[_kindle_quirks]]
661
+ .Kindle Quirks
662
+ * overrules margins and line heights like a medieval tyrant
663
+ * `font-family` can't be set on `<body>`
664
+ * requires `!important` on text-decoration
665
+ * `position: relative` isn't permitted
666
+ * strips (or unwraps) `<header>` tags
667
+ * `@page` isn't supported
668
+ * `page-break: avoid` isn't supported
669
+ * `max-width` isn't supported
670
+ * `widows` are left in the cold
671
+ * won't style footers without an explicit class
672
+
673
+ ////
674
+ head-stop (default '.')
675
+ stack-head role (run-in is default)
676
+ signature role (sets hardbreaks option)
677
+
678
+ subject-stop (default ':')
679
+ ////
680
+
681
+ ////
682
+ == Device and Application Testing
683
+
684
+ {project-name} has been tested on the following devices and applications.
685
+
686
+ .Computers
687
+ |===
688
+ |Device |OS |Resolution |ppi |Browsers |Readium |Gitden |Kindle
689
+
690
+ |Asus
691
+ |Fedora 17
692
+ |no x no
693
+ |
694
+ |Chrome x
695
+ |Readium
696
+
697
+ Asus, Fedora 20, display resolution, Chrome x, Readium
698
+ Ideapad Y460 |Fedora 20 |1366 x 768 (16:9) |
699
+ PC, Windows X,
700
+ |===
701
+
702
+ .Tablets
703
+ |===
704
+ Asus Transformer, Android x, display resolution, Aldiko, Kindle, Readium, Readmill
705
+ Nexus,
706
+ |===
707
+
708
+ .Phones
709
+ |===
710
+ HTC Sensation, Android x, display resolution, xxxx
711
+ Nexus ,
712
+ |===
713
+
714
+ ////
715
+
716
+ == Contributing
717
+
718
+ In the spirit of free software, _everyone_ is encouraged to help improve this project.
719
+
720
+ To contribute code, simply fork the project on GitHub, hack away and send a pull request with your proposed changes.
721
+
722
+ Feel free to use the {project-issues-uri}[issue tracker] or http://discuss.asciidoctor.org[Asciidoctor mailing list] to provide feedback or suggestions in other ways.
723
+
724
+ == Authors
725
+
726
+ {project-name} was written by https://github.com/mojavelinux[Dan Allen] and https://github.com/graphitefriction[Sarah White] of OpenDevise on behalf of the Asciidoctor Project.
727
+
728
+ == Copyright
729
+
730
+ Copyright (C) 2014 OpenDevise Inc. and the Asciidoctor Project.
731
+ Free use of this software is granted under the terms of the MIT License.
732
+
733
+ For the full text of the license, see the {license-uri}[LICENSE.adoc] file.
734
+ Refer to the {notice-uri}[NOTICE.adoc] file for information about third-party Open Source software in use.
735
+
736
+ ////
737
+ == Additional Points of Note
738
+
739
+ * uppercase chapter titles to work around line-height limitation in Kindle (1.4 minimum)
740
+ * circled numbers from M+ 1mn for annotation numbers in listing blocks
741
+ * avatars for authors
742
+ * document command to generate the M+ 1p latin fonts
743
+ * recommended readers (Readium, Gitden, Kindle, etc)
744
+ ////