Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "index"

r2epub can be used as a library module both to TypeScript and to Javascript. This module is the common entry point from both the cli or the serve functions for the command line interface and the server side, respectively. Furthermore, it provides an API that can be used directly; a simple example is as follows:

In Typescript (using node.js):

import * as r2epub  from 'r2epub';
import * as fs      from 'fs';
// The creation itself is asynchronous (the content has to be fetched over the wire).
// The result is the class instance encapsulating an OCF (zip) content
const url :string = "http://www.example.org/doc.html",
const args :r2epub.Options = {
    respec : false,
    config : {}
};
const ocf :r2epub.OCF = await r2epub.convert(url, args);
// The zip file is finalized asynchronously
const content :Buffer = await ocf.get_content();
// Get the content out to the disk
fs.writeFileSync(ocf.name, content);

The same in Javascript (using node.js):

const r2epub  = require('r2epub');
// The creation itself is asynchronous (the content has to be fetched over the wire).
// The result is the class instance encapsulating an OCF (zip) content
const url = "http://www.example.org/doc.html",
const args  = {
    respec : false,
    config : {}
};
const ocf = await r2epub.convert(url, args);
// The zip file is finalized asynchronously
const content = await ocf.get_content();
// Get the content out to the disk
fs.writeFileSync(ocf.name, content);

See the detailed specification of the API element below. The top level functional entry point to the package is convert.

Index

Classes

Interfaces

Functions

Functions

convert

  • convert(url: string, options?: Options, t?: boolean, p?: boolean): Promise<OCF>
  • The top level entry in the package: convert a single Respec file, or a collection thereof, into an EPUB document.

    async

    Parameters

    • url: string

      the URL of either the HTML content (if the target is a single document) or a JSON content (if the target is a collection of HTML documents)

    • Default value options: Options = {}

      ReSpec options in case the source has to be preprocessed by ReSpec

    • Default value t: boolean = false

      whether tracing is set (for debugging)

    • Default value p: boolean = false

      whether the package stops at the creation of an EPUB content and displays the content of the OPF file itself (for debugging)

    Returns Promise<OCF>