Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RespecToEPUB

Main processing steps for the creation of EPUB files. See the create_epub and create_epub_from_dom entry points for the details.

On a high level, the task of creating the EPUB file consists of:

  • Collect all the dependent resources like images, scripts, css files, audio, video, etc, that are "part" of the specification. In practical terms that means all resources with a relative URL should be collected.
  • Set the right CSS files. W3C TR documents refer (via absolute URL-s) to CSS files in https://www.w3.org/StyleSheet/TR/2016/*; these style files, and the related images, depend on the exact nature of the TR document: REC, WD, etc. All these should be collected/created as resources for the EPUB file. (See the “css” module.)
  • Follow similar actions for some system wide javascript files (although, at this moment, it is a single JS file that must be taken care of).
  • Extract the various metadata items (title, editors, dates, etc.) for the package file.
  • Remove the TOC from the TR document (i.e., making it display:none), extract that HTML fragment and put it into a separate nav file, per EPUB3 specification. (See the “nav” module.)
  • Create a title page. (See the title module.)
  • Create a cover image. (See the cover module.)
  • Extract OPF properties from the original HTML content to be added to spine entries. (See the “overview” module.)
  • Modify the DOM tree to abide to some specificities of reading systems (like Apple’s Books) and convert the result content into XHTML. (See the “overview” module.)
  • Create the package (OPF) file with the right resource and spine entries. (See the “opf” module.)
  • Create the OCF file (i.e., the final EPUB instance) containing all the resources collected and created in the previous steps. (See the “ocf” module.)

Hierarchy

Index

Constructors

constructor

  • new RespecToEPUB(trace?: boolean, print_package?: boolean): RespecToEPUB

Properties

Private global

global: Global

Private global_url

global_url: string

Private resource_references

resource_references: LocalLinks[] = [{query : 'img, script, audio, video, source',attr : 'src',},{query : 'a, link[rel="stylesheet"]',attr : 'href',},{query : 'object',attr : 'data',},]

Arrays of query/attribute pairs that may refer to a resource to be collected:

  • image, audio, and video, elements
  • a elements
  • links to stylesheets and scripts
  • object elements

Methods

create_epub

  • create_epub(url: string, options: Options): Promise<OCF>
  • Create an EPUB 3.2, ie, an OCF file from the original content

    This function is a wrapper around create_epub_from_dom:

    1. Creates the DOM, which means, possibly, the original content is ran through the respec processor (if necessary).
    2. Calls create_epub_from_dom to generate the OCF content.
    3. "Finalizes" the OCF content, i.e., dump everything to a file.
    async

    Parameters

    • url: string
    • options: Options

      Reference to the original document; this may have to be transformed by respec on-the-fly.

    Returns Promise<OCF>

create_epub_from_dom

  • create_epub_from_dom(url: string, dom: JSDOM): Promise<OCF>
  • Create an OCF instance from DOM representing the original content.

    1. Gather all the global information (Global).
    2. Add the basic metadata (authors, dates) to the opf file.
    3. Collect all the resources (see resource_references); the relative urls and the media types are collected in a global structure, to be added to the EPUB file and the opf file later.
    4. Add the reference to a W3C logo.
    5. Add the reference to the generic fixup script.
    6. Add some of the global W3C CSS files, and auxiliary image files.
    7. Create a title page.
    8. Create a cover image.
    9. Create a nav file.
    10. Main resource (i.e., Overview.xhtml) entry, with relevant properties.
    11. Finalize the package file based on the collected resources in Global.resources.
    12. Download all resources into the EPUB file.

    All the resource entries are first collected in the in a Global.resources array, to be then added to the package.opf file as well as to download the resources into the final epub result (see the last two steps above).

    async

    Parameters

    • url: string

      The url of the document (serves also as a base for all the other resources)

    • dom: JSDOM

      The DOM of the final format of the document (i.e., the original document may have gone through a respec processing...)

    Returns Promise<OCF>

    • The zip archive with the epub content, i.e., an OCF instance

Private generate_epub

  • generate_epub(): Promise<OCF>
  • Create the final epub file (ie, an OCF instance): download all resources, if applicable, add them all, as well as the generated content (package file, nav file, the original content file, etc.) to an OCF instance.

    The generated epub file name is shortName.epub.

    async

    Returns Promise<OCF>

Private get_extra_resources

  • Collect the references to the extra resources, to be added to the EPUB file as well as the package opf file. It relies on searching through the HTML source file, based on the query patterns given in resource_references.

    The media type of all entries are established by issuing a HEAD request to the respective resource.

    async

    Returns Promise<ResourceRef[]>

    • list of additional resources