epub

package
v0.0.0-...-c5bc608 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContainerFilename = "META-INF/container.xml" // filename of container.xml
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	Container xml.Name `xml:"container"`
	XMLNS     string   `xml:"xmlns,attr"`
	Version   string   `xml:"version,attr"`
	Rootfiles []struct {
		Rootfile  xml.Name `xml:"rootfile"`
		FullPath  string   `xml:"full-path,attr"`
		MediaType string   `xml:"media-type,attr"`
	} `xml:"rootfiles>rootfile"`
}

type Epub

type Epub struct {
	Filename  string
	Container Container
	Rootfile  Rootfile
	Toc       Toc
	SeqFiles  []*zip.File
	Files     map[string]*zip.File

	Styles []*cssparser.Rule
	// contains filtered or unexported fields
}

func NewEpub

func NewEpub(filename string) *Epub

func (*Epub) Close

func (epub *Epub) Close()

func (*Epub) GetContentByHref

func (epub *Epub) GetContentByHref(href HRef) (string, error)

GetContentByHref return file content by href(setted in spine)

func (*Epub) GetContentByManifestId

func (epub *Epub) GetContentByManifestId(id ManifestId) (string, error)

GetContentByManifestId return file content by manifest id

func (*Epub) GetFullPath

func (epub *Epub) GetFullPath(href HRef) string

GetFullPath return full filepath(relative to rootfile) by href(setted in spine)

func (*Epub) GetNextSection

func (epub *Epub) GetNextSection(id ManifestId) (string, ManifestId, error)

func (*Epub) GetPrevSection

func (epub *Epub) GetPrevSection(id ManifestId) (string, ManifestId, error)

func (*Epub) GetSpinContent

func (epub *Epub) GetSpinContent() (*SpineContent, error)

GetSpinContent return all spine content in `href: html content` format

func (*Epub) GetTableOfContent

func (epub *Epub) GetTableOfContent() *TableOfContent

func (*Epub) HrefToManifestId

func (epub *Epub) HrefToManifestId(href HRef) ManifestId

func (*Epub) ManifestIdToHref

func (epub *Epub) ManifestIdToHref(id ManifestId) HRef

func (*Epub) Open

func (epub *Epub) Open() error

func (*Epub) Title

func (epub *Epub) Title() string

type HRef

type HRef string

type ManifestId

type ManifestId string

This the manifest item id of the epub content

type Rootfile

type Rootfile struct {
	Metadata struct {
		Rights      string `xml:"rights"`
		ISBN        string `xml:"identifier"`
		Title       string `xml:"title"`
		Description string `xml:"description"`
		Creator     string `xml:"creator"`
		Date        string `xml:"date"`
		Publisher   string `xml:"publisher"`
		Language    string `xml:"language"`
		Format      string `xml:"format"`
	} `xml:"metadata"`
	Manifest struct {
		Items []struct {
			ID        ManifestId `xml:"id,attr"`
			Href      HRef       `xml:"href,attr"`
			MediaType string     `xml:"media-type,attr"`
		} `xml:"item"`
	} `xml:"manifest"`
	Spine struct {
		TocID ManifestId `xml:"toc,attr"`
		Items []struct {
			IDref ManifestId `xml:"idref,attr"`
			Link  string     `xml:"linear,attr"`
		} `xml:"itemref"`
	} `xml:"spine"`
	Guide struct {
		Items []struct {
			Type  string `xml:"type,attr"`
			Href  string `xml:"href,attr"`
			Title string `xml:"title"`
		} `xml:"reference"`
	} `xml:"guide"`
}

type SpineContent

type SpineContent struct {
	Orders   []ManifestId
	Contents map[ManifestId]string
}

type TableOfContent

type TableOfContent struct {
	Orders  []string // Titles in order
	Content map[string]struct {
		Level int
		ID    ManifestId
	}
}

type Toc

type Toc struct {
	Head struct {
		Metas []struct {
			Name  string `xml:"name,attr"`
			Value string `xml:"content,attr"`
		} `xml:"meta"`
	} `xml:"head"`
	DocTitle struct {
		Text string `xml:",chardata"`
	} `xml:"docTitle"`
	NavMap struct {
		//TODO(elinx): better way to express nested navPoint
		NavPoints []struct {
			ID        string `xml:"id,attr"`
			PlayOrder string `xml:"playOrder,attr"`
			NavLable  struct {
				Text string `xml:",chardata"`
			} `xml:"navLabel>text"`
			Content struct {
				Src HRef `xml:"src,attr"`
			} `xml:"content"`
			NavPoints []navPoint `xml:"navPoint"`
		} `xml:"navPoint"`
	} `xml:"navMap"`
}

Jump to

Keyboard shortcuts

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