teapub
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

TeaPub 🍵🍺

build docs npm license

A pure TypeScript preact-based library for generating ePub files. In contrast to html-to-epub and nodepub, this runs in any javascript environment and seeks a more minimal approach to ePub generation rather than autogenerating content like a cover and table of contents.

Usage

A minimal example

import { render } from "teapub";

const buffer = await render({
  title: "title",
  sections: [{
    title: "section title",
    content: "<my html>",
  }],
});

This library can also include images encoded as buffers. To include them, add an images mapping that maps the src attribute of images in the included html to buffers with optional mime type.

import { readFile } from "fs/promises";
import { render } from "teapub";

const data = await readFile("myfile.jpg");

const buffer = await render({
  title: "title",
  sections: [{
    title: "section title",
    content: `<img src="myfile.jpg"></img>`,
  }],
  images: new Map([["myfile.jpg", { data }]]),
});

Missing

This is intended as barebones, so a lot of aspects related to generating "books" as epubs are missing, but easily includable upon request:

  • [ ] custom fonts
  • [ ] covers, custom or otherwise
  • [ ] table of contents page, custom or otherwise
  • [ ] customizable node and attribute filtering

/teapub/

    Package Sidebar

    Install

    npm i teapub

    Weekly Downloads

    35

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    463 kB

    Total Files

    32

    Last publish

    Collaborators

    • erik.brinkman