epub

package module
v0.0.0-...-c19055c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 8 Imported by: 1

README

epub

Golang epub reader library

Summary

  • Written on pure Go
  • Require Go version >= 1.14

Install

go get github.com/wmentor/epub

Usage

package main

import (
  "fmt"
  "os"

  "github.com/wmentor/epub"
)

func main() {

  err := epub.Reader("./data/test.epub", func(chapter string, chapterHTML []byte) bool {
    fmt.Println(chapter)
  })
  if err != nil {
    panic(err)
  }

  // print epub to Stdout as text
  epub.ToTxt("./data/test.epub", os.Stdout)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reader

func Reader(filename string, onChapter func(chapter string, data []byte) bool) error

func ToTxt

func ToTxt(filename string, output io.Writer) error

Types

type Author

type Author struct {
	Data   string `xml:",chardata"`
	FileAs string `xml:"file-as,attr"`
	Role   string `xml:"role,attr"`
}

type Book

type Book struct {
	Ncx       Ncx
	Opf       Opf
	Container Container
	Mimetype  string
	// contains filtered or unexported fields
}

func Open

func Open(fn string) (*Book, error)

func (*Book) Close

func (p *Book) Close()

func (*Book) Files

func (p *Book) Files() []string

func (*Book) Open

func (p *Book) Open(n string) (io.ReadCloser, error)

type Container

type Container struct {
	Rootfile Rootfile `xml:"rootfiles>rootfile" json:"rootfile"`
}

type Content

type Content struct {
	Src string `xml:"src,attr"`
}

type Date

type Date struct {
	Data  string `xml:",chardata"`
	Event string `xml:"event,attr"`
}

type Identifier

type Identifier struct {
	Data   string `xml:",chardata"`
	ID     string `xml:"id,attr"`
	Scheme string `xml:"scheme,attr"`
}

type Manifest

type Manifest struct {
	ID           string `xml:"id,attr"`
	Href         string `xml:"href,attr"`
	MediaType    string `xml:"media-type,attr"`
	Fallback     string `xml:"media-fallback,attr"`
	Properties   string `xml:"properties,attr"`
	MediaOverlay string `xml:"media-overlay,attr"`
}

type Metadata

type Metadata struct {
	Title       []string     `xml:"title"`
	Language    []string     `xml:"language"`
	Identifier  []Identifier `xml:"identifier"`
	Creator     []Author     `xml:"creator"`
	Subject     []string     `xml:"subject"`
	Description []string     `xml:"description"`
	Publisher   []string     `xml:"publisher"`
	Contributor []Author     `xml:"contributor"`
	Date        []Date       `xml:"date"`
	Type        []string     `xml:"type"`
	Format      []string     `xml:"format"`
	Source      []string     `xml:"source"`
	Relation    []string     `xml:"relation"`
	Coverage    []string     `xml:"coverage"`
	Rights      []string     `xml:"rights"`
	Meta        []Metafield  `xml:"meta"`
}

type Metafield

type Metafield struct {
	Name    string `xml:"name,attr"`
	Content string `xml:"content,attr"`
}
type NavPoint struct {
	Text    string     `xml:"navLabel>text"`
	Content Content    `xml:"content"`
	Points  []NavPoint `xml:"navPoint"`
}

type Ncx

type Ncx struct {
	Points []NavPoint `xml:"navMap>navPoint"`
}

type Opf

type Opf struct {
	Metadata Metadata   `xml:"metadata"`
	Manifest []Manifest `xml:"manifest>item"`
	Spine    Spine      `xml:"spine"`
}

type Rootfile

type Rootfile struct {
	Path string `xml:"full-path,attr"`
	Type string `xml:"media-type,attr"`
}

type Spine

type Spine struct {
	ID              string      `xml:"id,attr"`
	Toc             string      `xml:"toc,attr"`
	PageProgression string      `xml:"page-progression-direction,attr"`
	Items           []SpineItem `xml:"itemref"`
}

type SpineItem

type SpineItem struct {
	IDref      string `xml:"idref,attr"`
	Linear     string `xml:"linear,attr"`
	ID         string `xml:"id,attr"`
	Properties string `xml:"properties,attr"`
}

Jump to

Keyboard shortcuts

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