epub

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package epub creates EPUB files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Identifier

type Identifier struct {
	XMLName xml.Name `xml:"dc:identifier"`
	Value   string   `xml:",chardata"`
	ID      string   `xml:"id,attr"`
	Scheme  string   `xml:"opf:scheme,attr"`
}

Identifier is the metadata>dc:identifier tag.

type Manifest

type Manifest struct {
	XMLName xml.Name `xml:"manifest"`
	Items   []ManifestItem
}

Manifest is the package>manifest tag.

type ManifestItem

type ManifestItem struct {
	XMLName   xml.Name `xml:"item"`
	ID        string   `xml:"id,attr"`
	Href      string   `xml:"href,attr"`
	MediaType string   `xml:"media-type,attr"`
}

ManifestItem is a manifest>item tag.

type Metadata

type Metadata struct {
	XMLName    xml.Name   `xml:"metadata"`
	XMLnsDC    string     `xml:"xmlns:dc,attr"`
	XMLnsOPF   string     `xml:"xmlns:opf,attr"`
	Identifier Identifier `xml:"dc:identifier"`
	Language   string     `xml:"dc:language"`
	Title      string     `xml:"dc:title"`
}

Metadata is the package>metadata tag.

type Package

type Package struct {
	XMLName  xml.Name `xml:"package"`
	Version  string   `xml:"version,attr"`
	XMLns    string   `xml:"xmlns,attr"`
	UniqueID string   `xml:"unique-identifier,attr"`
	Metadata Metadata
	Manifest Manifest
	Spine    Spine
}

Package is the root of content.opf.

func NewPackage

func NewPackage() Package

NewPackage returns a new Package instance with default values.

type Spine

type Spine struct {
	XMLName xml.Name `xml:"spine"`
	Toc     string   `xml:"toc,attr"`
	Items   []SpineItem
}

Spine is the package>spine tag.

type SpineItem

type SpineItem struct {
	XMLName xml.Name `xml:"itemref"`
	IDRef   string   `xml:"idref,attr"`
	Title   string   `xml:"-"`
	Src     string   `xml:"-"`
}

SpineItem is a spine>itemref tag.

type TOC

type TOC struct {
	XMLName xml.Name  `xml:"ncx"`
	XMLns   string    `xml:"xmlns,attr"`
	Version string    `xml:"version,attr"`
	Meta    []TOCMeta `xml:"head>meta"`
	Title   string    `xml:"docTitle>text"`
	Author  string    `xml:"docAuthor>text"`
	Nav     []TOCNav  `xml:"navMap>navPoint"`
}

TOC is the root of the toc.ncx file.

type TOCMeta

type TOCMeta struct {
	Name    string `xml:"name,attr"`
	Content string `xml:"content,attr"`
}

TOCMeta is a ncx>head>meta tag.

type TOCNav

type TOCNav struct {
	ID    string `xml:"id,attr"`
	Title string `xml:"navLabel>text"`
	Src   TOCNavSrc
}

TOCNav is a ncx>navMap>navPoint tag.

type TOCNavSrc

type TOCNavSrc struct {
	XMLName xml.Name `xml:"content"`
	Src     string   `xml:"src,attr"`
}

TOCNavSrc is ncx>navMap>navPoint>content tag.

type Writer

type Writer struct {
	*zip.Writer
	// contains filtered or unexported fields
}

Writer is an EPUB container. It's basically a wrapper around a zip.Writer with some additional methods to handle epub specificities.

func New

func New(w io.Writer) *Writer

New creates a new EpubFile instance.

func (*Writer) AddChapter

func (c *Writer) AddChapter(id, title, name string, r io.Reader) error

AddChapter adds a new chapter to the book.

func (*Writer) AddFile

func (c *Writer) AddFile(id, name, mediaType string, r io.Reader) error

AddFile adds a file to the book.

func (*Writer) AddImage

func (c *Writer) AddImage(id, name string, r io.Reader) error

AddImage adds an image to the book with automatic media type detection.

func (*Writer) Bootstrap

func (c *Writer) Bootstrap() (err error)

Bootstrap adds the necessary files to the EPUB container.

func (*Writer) SetID

func (c *Writer) SetID(value string)

SetID sets the book's unique ID.

func (*Writer) SetLanguage

func (c *Writer) SetLanguage(value string)

SetLanguage sets the book's main language.

func (*Writer) SetTitle

func (c *Writer) SetTitle(value string)

SetTitle sets the book's title.

func (*Writer) WritePackage

func (c *Writer) WritePackage() error

WritePackage finishes the book creation by adding a content.opf and a toc.ncx files based on all the files added earlier.

Jump to

Keyboard shortcuts

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