epub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LinkCSS = `<link href="style.css" rel="stylesheet" type="text/css"/>`

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	// Body contains the actual HTML/text data for this section.
	Body body.Body
	// ReferenceType defines the semantic nature (e.g., Preface, Text, Index).
	ReferenceType reftype.ReferenceType
	// SubContents allows for hierarchical nesting of chapters (e.g., Part > Chapter).
	SubContents []Content
	// ContentReferences defines internal navigational points within this content.
	ContentReferences []ContentReference
	// Filename is an optional custom name for the generated XHTML file.
	Filename nilo.Option[string]
}

Content represents a chapter, section, or specific semantic block within the EPUB. It supports recursive nesting via SubContents and internal cross-linking via ContentReferences.

func (Content) CreateFileContent

func (c Content) CreateFileContent(number *int, stylesheet string) ([]files.FileContent[string], error)

CreateFileContent recursively generates a slice of FileContent objects. It wraps the raw body in a valid XHTML 1.1 template, applies the stylesheet, and places the resulting files into the "OEBPS/" directory.

func (Content) GetFilename

func (c Content) GetFilename(number int) string

GetFilename returns the user-defined filename or generates a default sequential one (e.g., "c01.xhtml") based on the provided index.

func (Content) Level

func (c Content) Level() int

Level calculates the maximum depth of the nested SubContents tree. A content block with no children returns 0.

func (Content) LevelReferenceContent

func (c Content) LevelReferenceContent() int

LevelReferenceContent calculates the maximum nesting depth of the tree, accounting for both SubContents and ContentReferences.

type ContentReference

type ContentReference struct {
	// Title is the text displayed in the navigation menu.
	Title string
	// SubContentReferences allows for nested navigation levels (e.g., Chapter 1 > Section A).
	SubContentReferences []ContentReference
	// ID is an optional HTML anchor ID within the target file.
	ID nilo.Option[string]
}

ContentReference represents a navigational entry point within a content file. It is used to generate Table of Contents (ToC) entries that can point to specific anchors or headers within a section.

func (ContentReference) ReferenceName

func (cr ContentReference) ReferenceName(xhtml string, number int) string

ReferenceName constructs a full URI for the reference, combining the XHTML filename with an anchor fragment. If no ID is provided, it generates a default fragment (e.g., "filename.xhtml#id01").

type Epub

type Epub struct {
	// Metadata contains the bibliographic information for the publication.
	Metadata Metadata
	// Stylesheet is an optional global CSS body applied to all content sections.
	Stylesheet nilo.Option[body.Body]
	// CoverImage is the optional image designated as the book's front cover.
	CoverImage nilo.Option[resource.Image]
	// Resources is a collection of secondary assets like fonts, audio, or video.
	Resources []resource.Resource
	// Contents holds the primary reading order and structural sections of the book.
	Contents []Content
}

Epub represents the complete structure of an EPUB document. It serves as the root container that holds metadata, styling, embedded resources, and the hierarchical content tree.

func (Epub) Level

func (e Epub) Level() int

Level calculates the maximum depth of the entire EPUB's navigation and content tree. It evaluates both nested SubContents and ContentReferences across all root-level items to determine the structural complexity of the document.

type Metadata

type Metadata struct {
	// Title is the primary name of the publication.
	Title string
	// Language defines the primary language of the content (ISO 639-1).
	Language lang.Language
	// Identifier is the unique ID for the book (e.g., UUID or ISBN).
	Identifier ident.Identifier
	// Creator is the primary author or organization responsible for the work.
	Creator nilo.Option[string]
	// Contributor is an entity that made secondary contributions.
	Contributor nilo.Option[string]
	// Publisher is the entity responsible for publication.
	Publisher nilo.Option[string]
	// Date is the publication or creation timestamp.
	Date nilo.Option[time.Time]
	// Subject defines the keywords or categories for the book.
	Subject nilo.Option[string]
	// Description is a summary or abstract of the content.
	Description nilo.Option[string]
}

Metadata represents the Dublin Core metadata elements for the EPUB. It includes mandatory fields like Title, Language, and Identifier, along with optional bibliographic descriptors.

Jump to

Keyboard shortcuts

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