Documentation
ΒΆ
Index ΒΆ
- type Epub
- type PublicationResource
- type Reader
- func (r *Reader) Author() (author string)
- func (r *Reader) ContentDocumentMarkdown() (documents map[string]string)
- func (r *Reader) ContentDocumentSVG() (documents map[string]*html.Node)
- func (r *Reader) ContentDocumentXHTML() (documents map[string]*html.Node)
- func (r *Reader) ContentDocumentXHTMLString() (documents map[string]string)
- func (r *Reader) Cover() (cover *image.Image)
- func (r *Reader) CoverBytes() (cover []byte, err error)
- func (r *Reader) CurrentSelectedPackage() *pkg.Package
- func (r *Reader) CurrentSelectedPackagePath() string
- func (r *Reader) Description() (description string)
- func (r *Reader) Identifier() (identifier string)
- func (r *Reader) ImageResources() (images map[string][]byte)
- func (r *Reader) Images() (images map[string]image.Image)
- func (r *Reader) Language() (language string)
- func (r *Reader) ListContentDocumentIds() (ids []string)
- func (r *Reader) ListImageIds() (ids []string)
- func (r *Reader) Metadata() (metadata map[string]any)
- func (r *Reader) NavigationCenterExtended() *ncx.NCX
- func (r *Reader) ReadContentHTMLByHref(href string) (doc *html.Node)
- func (r *Reader) ReadContentHTMLById(id string) (doc *html.Node)
- func (r *Reader) ReadContentMarkdownById(id string) (md string)
- func (r *Reader) ReadImageByHref(href string) (img *image.Image)
- func (r *Reader) ReadImageById(id string) (img *image.Image)
- func (r *Reader) References() (references map[pkg.GuideReferenceType]*html.Node)
- func (r *Reader) Refines() (refines map[string]map[string][]string)
- func (r *Reader) Resources() (resources []PublicationResource)
- func (r *Reader) SelectPackageRendition(rendition string)
- func (r *Reader) SelectResourceByHref(href string) (resource *PublicationResource)
- func (r *Reader) SelectResourceById(id string) (resource *PublicationResource)
- func (r *Reader) Spine() (orderedResources []PublicationResource)
- func (r *Reader) TableOfContents() (toc TOC, err error)
- func (r *Reader) Title() (title string)
- func (r *Reader) UID() (identifier string)
- func (r *Reader) Version() (version string)
- type TOC
- type Writer
- func (w *Writer) AddContent(filename string, content []byte) (res PublicationResource)
- func (w *Writer) AddContentFile(name string) (res PublicationResource, err error)
- func (w *Writer) AddGuide(kind pkg.GuideReferenceType, href string, title string)
- func (w *Writer) AddImage(name string, content []byte) (res PublicationResource)
- func (w *Writer) AddImageFile(name string) (res PublicationResource)
- func (w *Writer) AddSpineItem(res PublicationResource)
- func (w *Writer) Author(creator string)
- func (w *Writer) Contributor(kind string, contributor string)
- func (w *Writer) Cover(cover []byte) (err error)
- func (w *Writer) CoverFile(name string)
- func (w *Writer) CoverJPG(cover image.Image) (err error)
- func (w *Writer) CoverPNG(cover image.Image) (err error)
- func (w *Writer) Creator(id string, creator string)
- func (w *Writer) Date(date time.Time)
- func (w *Writer) Description(description string)
- func (w *Writer) Direction(dir string)
- func (w *Writer) DublinCores(keyVal map[string]string)
- func (w *Writer) Identifiers(identifier ...string)
- func (w *Writer) Languages(language ...string)
- func (w *Writer) LongDescription(description string)
- func (w *Writer) Meta(meta pkg.Meta)
- func (w *Writer) MetaContent(keyVal map[string]string)
- func (w *Writer) MetaProperty(id string, property string, value string)
- func (w *Writer) Publisher(publisher string)
- func (w *Writer) Refines(refines string, property string, value string, otherAttributes ...pkg.Meta)
- func (w *Writer) Rights(rights string)
- func (w *Writer) SetContentDir(dir string)
- func (w *Writer) SetImageDir(dir string)
- func (w *Writer) SetTextDir(dir string)
- func (w *Writer) Subject(id string, subject string)
- func (w *Writer) TableOfContents(name string, toc TOC) (err error)
- func (w *Writer) Title(title ...string)
- func (w *Writer) Write(filename string) (err error)
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Epub ΒΆ
type Epub struct {
// contains filtered or unexported fields
}
Epub represents a full EPUB publication, including metadata, package information, resources, and navigation.
func (*Epub) DefaultPackage ΒΆ added in v0.2.0
func (*Epub) SelectPackage ΒΆ added in v0.2.0
func (*Epub) SelectedPackage ΒΆ added in v0.2.0
type PublicationResource ΒΆ
type PublicationResource struct {
ID string
Href string
MIMEType string
Content []byte
Filepath string
Properties pkg.ManifestProperty
}
PublicationResource represents a single resource inside the EPUB container. Resources may include XHTML documents, images, stylesheets, SVG files, and auxiliary data referenced by the publication manifest.
type Reader ΒΆ
type Reader struct {
// contains filtered or unexported fields
}
Reader provides an interface for reading and accessing EPUB publication data. It offers methods for retrieving metadata, navigation structures, content documents, resources, and images.
func NewReader ΒΆ
NewReader creates a new Reader instance from a raw EPUB byte slice. The byte slice must represent a valid EPUB container.
func OpenReader ΒΆ
OpenReader opens an EPUB file from the provided file path and returns a Reader instance. The file must exist and be a valid EPUB container.
func (*Reader) ContentDocumentMarkdown ΒΆ
ContentDocumentMarkdown returns content documents converted into Markdown form. The returned map is keyed by EPUB manifest item ID.
func (*Reader) ContentDocumentSVG ΒΆ
ContentDocumentSVG returns SVG content documents parsed into html.Node trees. The returned map is keyed by EPUB manifest item ID.
func (*Reader) ContentDocumentXHTML ΒΆ
ContentDocumentXHTML returns XHTML content documents parsed into html.Node trees. The returned map is keyed by EPUB manifest item ID.
func (*Reader) ContentDocumentXHTMLString ΒΆ
ContentDocumentXHTMLString returns XHTML content documents as raw strings. The returned map is keyed by EPUB manifest item ID.
func (*Reader) CoverBytes ΒΆ added in v0.2.0
CoverBytes returns the raw byte representation of the cover image. An error is returned if the publication does not define a cover.
func (*Reader) CurrentSelectedPackage ΒΆ
CurrentSelectedPackage returns the currently active package rendition. EPUB publications may have multiple renditions.
func (*Reader) CurrentSelectedPackagePath ΒΆ
CurrentSelectedPackagePath returns the internal path to the currently selected package document.
func (*Reader) Description ΒΆ
Description returns the publication's description metadata if defined.
func (*Reader) Identifier ΒΆ added in v0.2.0
Identifier returns the primary identifier of the publication as declared in the package metadata (often equivalent to UID).
func (*Reader) ImageResources ΒΆ added in v0.2.0
ImageResources returns all image resources in byte form, keyed by manifest ID. Useful when direct decoding to image.Image is not required.
func (*Reader) Images ΒΆ
Images returns all image resources in the publication, keyed by manifest ID.
func (*Reader) Language ΒΆ added in v0.2.0
Language returns the primary language of the publication, as declared in the package metadata (dc:language).
func (*Reader) ListContentDocumentIds ΒΆ added in v0.1.2
ListContentDocumentIds returns the IDs of all content documents (XHTML/SVG) registered in the publication manifest.
func (*Reader) ListImageIds ΒΆ added in v0.1.2
ListImageIds returns the IDs of all image-based resources (e.g., PNG, JPEG, SVG) in the publication manifest.
func (*Reader) Metadata ΒΆ
Metadata returns the complete metadata block of the publication. The returned map may include standard as well as extended metadata fields.
func (*Reader) NavigationCenterExtended ΒΆ
NavigationCenterExtended returns the NCX navigation document (if available). This is primarily used for EPUB 2.x backward compatibility.
func (*Reader) ReadContentHTMLByHref ΒΆ added in v0.1.3
ReadContentHTMLByHref returns the content document associated with the given manifest href. The returned document is parsed into an html.Node tree.
func (*Reader) ReadContentHTMLById ΒΆ
ReadContentHTMLById returns the XHTML/HTML content document associated with the given manifest ID, parsed into an html.Node tree.
func (*Reader) ReadContentMarkdownById ΒΆ added in v0.1.1
ReadContentMarkdownById returns a Markdown string representation of the content document associated with the given manifest ID.
func (*Reader) ReadImageByHref ΒΆ
ReadImageByHref returns the image resource referenced by the given href, if present in the manifest.
func (*Reader) ReadImageById ΒΆ
ReadImageById returns the image resource associated with the given manifest ID.
func (*Reader) References ΒΆ added in v0.2.1
func (r *Reader) References() (references map[pkg.GuideReferenceType]*html.Node)
References returns the structural guide references defined in the package, such as "cover", "title-page", "toc", etc. The returned map is keyed by reference type and mapped to corresponding HTML content.
func (*Reader) Refines ΒΆ
Refines returns metadata refinement relationships. The returned map is keyed by subject identifier, mapping to properties and their assigned values.
func (*Reader) Resources ΒΆ
func (r *Reader) Resources() (resources []PublicationResource)
Resources returns all publication resources declared in the manifest.
func (*Reader) SelectPackageRendition ΒΆ
SelectPackageRendition changes the active package rendition by its rendition identifier. Useful when multiple reading layouts are available.
func (*Reader) SelectResourceByHref ΒΆ
func (r *Reader) SelectResourceByHref(href string) (resource *PublicationResource)
SelectResourceByHref retrieves a resource referenced by its manifest href.
func (*Reader) SelectResourceById ΒΆ
func (r *Reader) SelectResourceById(id string) (resource *PublicationResource)
SelectResourceById retrieves a resource referenced by its manifest ID.
func (*Reader) Spine ΒΆ
func (r *Reader) Spine() (orderedResources []PublicationResource)
Spine returns publication's spines, ordered resources like table of contents.
func (*Reader) TableOfContents ΒΆ
TableOfContents returns the TOC version present (e.g., NAV or NCX). If both exist, behavior depends on publication version and priority rules.
type TOC ΒΆ added in v0.1.3
type TOC struct {
Title string `json:"title,omitempty"`
Href string `json:"href,omitempty"`
Items []TOC `json:"items,omitempty"`
// contains filtered or unexported fields
}
TOC represents the publication's table of contents in normalized form. The structure abstracts differences between NAV (EPUB 3) and NCX (EPUB 2) so higher-level code can work with a unified interface.
func (*TOC) JSON ΒΆ added in v0.1.3
JSON marshals the table of contents structure into JSON format. This is useful for external tools, logging, debugging, or serialization to other formats.
func (*TOC) ReadContentHTML ΒΆ added in v0.1.3
ReadContentHTML returns the content document associated with the currently selected table of contents entry. The returned document is parsed into an html.Node tree. Behavior depends on TOC internal navigation selection state.
type Writer ΒΆ
type Writer struct {
// contains filtered or unexported fields
}
Writer provides an interface for constructing, modifying, and writing EPUB publications to disk or memory. Writer usage documentation is evolving.
func New ΒΆ added in v0.2.0
New creates a new Writer with the given publication identifier. The identifier is assigned to the package metadata (dc:identifier).
func (*Writer) AddContent ΒΆ added in v0.2.0
func (w *Writer) AddContent(filename string, content []byte) (res PublicationResource)
AddContent adds a content file (such as XHTML or SVG) to the publication using the provided filename and raw bytes. Returns the created resource.
func (*Writer) AddContentFile ΒΆ added in v0.2.0
func (w *Writer) AddContentFile(name string) (res PublicationResource, err error)
AddContentFile adds a content file to the publication by reading the file from disk. Returns the created resource and any file access error.
func (*Writer) AddGuide ΒΆ added in v0.2.0
func (w *Writer) AddGuide(kind pkg.GuideReferenceType, href string, title string)
AddGuide adds a guide reference entry (e.g., "cover", "toc", "title-page") to the package metadata.
func (*Writer) AddImage ΒΆ added in v0.2.0
func (w *Writer) AddImage(name string, content []byte) (res PublicationResource)
AddImage adds an image resource from raw bytes to the publication.
func (*Writer) AddImageFile ΒΆ added in v0.2.0
func (w *Writer) AddImageFile(name string) (res PublicationResource)
AddImageFile adds an image resource to the publication by reading from disk.
func (*Writer) AddSpineItem ΒΆ added in v0.2.0
func (w *Writer) AddSpineItem(res PublicationResource)
AddSpineItem appends the given resource to the spine reading order.
func (*Writer) Author ΒΆ added in v0.2.0
Author sets the primary creator/author in the package metadata.
func (*Writer) Contributor ΒΆ added in v0.2.0
Contributor adds a contributor entry of the specified role or type.
func (*Writer) Cover ΒΆ added in v0.2.0
Cover sets the publication cover from a raw image byte slice.
func (*Writer) CoverFile ΒΆ added in v0.2.0
CoverFile sets the publication cover image by file path.
func (*Writer) CoverJPG ΒΆ added in v0.2.0
CoverJPG sets the publication cover image from an image.Image encoded as JPEG.
func (*Writer) CoverPNG ΒΆ added in v0.2.0
CoverPNG sets the publication cover image from an image.Image encoded as PNG
func (*Writer) Creator ΒΆ added in v0.2.0
Creator adds a creator with a specific identifier attribute to the metadata.
func (*Writer) Description ΒΆ added in v0.2.0
Description sets a short description or summary for the publication.
func (*Writer) Direction ΒΆ added in v0.2.0
Direction sets the writing direction (ltr or rtl) used by the spine.
func (*Writer) DublinCores ΒΆ added in v0.2.0
DublinCores sets multiple Dublin Core metadata fields at once.
func (*Writer) Identifiers ΒΆ added in v0.2.0
Identifiers adds one or more identifiers to the package metadata.
func (*Writer) Languages ΒΆ added in v0.2.0
Languages adds one or more language codes to the publication metadata.
func (*Writer) LongDescription ΒΆ added in v0.2.0
LongDescription sets an extended descriptive summary.
func (*Writer) MetaContent ΒΆ added in v0.2.0
MetaContent adds metadata key/value entries that do not require refinements.
func (*Writer) MetaProperty ΒΆ added in v0.2.0
MetaProperty adds a property-based metadata refinement entry.
func (*Writer) Refines ΒΆ added in v0.2.0
func (w *Writer) Refines(refines string, property string, value string, otherAttributes ...pkg.Meta)
Refines applies a metadata refinement to an existing metadata item.
func (*Writer) Rights ΒΆ added in v0.2.0
Rights sets the copyright or licensing information for the publication.
func (*Writer) SetContentDir ΒΆ added in v0.2.0
SetContentDir sets the directory used for storing content documents.
func (*Writer) SetImageDir ΒΆ added in v0.2.0
SetImageDir sets the directory used for storing image resources.
func (*Writer) SetTextDir ΒΆ added in v0.2.0
SetTextDir sets the directory used for text document organization.
func (*Writer) Subject ΒΆ added in v0.2.0
Subject adds a subject or theme classification to the publication.