epubwrite

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package epubwrite renders a cssbox tree (the shared box model produced by the HTML, DOCX, Markdown, and PDF-extraction frontends) to an EPUB 3 package. It is a STRUCTURE writer built on the htmlwrite serializer (EPUB content documents ARE XHTML): the document splits into chapters at each <h1> (content before the first — or a document with no <h1> at all — is a single untitled chapter), a nav.xhtml table of contents is built from the chapter titles, and images referenced through the resource loader embed as manifest items (data: URIs stay inline — they round-trip verbatim).

Output is deterministic: fixed zip timestamps and part order, the spec-required stored (uncompressed) "mimetype" as the first entry, and a fixed dcterms:modified stamp.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(ctx context.Context, root *cssbox.Box, w io.Writer, opts Options) error

Write renders the cssbox tree rooted at root to w as a complete .epub package. root is expected to be a finalized tree (post box-generation fixups). A nil root writes a valid one-empty-chapter book.

Types

type Options

type Options struct {
	// Title is the book's dc:title; the first <h1>'s text when empty, else
	// "Document".
	Title string
	// Loader resolves image refs (an <img> src) to bytes for embedding as
	// manifest items. data: URIs stay inline without a loader; for the rest,
	// nil means the reference is kept as-is (logged — it will not resolve
	// inside the container).
	Loader resource.ResourceLoader
	// Logf receives degradation diagnostics. nil -> no-op.
	Logf func(string, ...any)
}

Options configures EPUB output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL