packagefile

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ISO8601Date = `2006-01-02`

Variables

This section is empty.

Functions

This section is empty.

Types

type Contributor

type Contributor struct {
	DCMESOptionalElement
}

type Coverage

type Coverage struct {
	DCMESOptionalElement
}

type Creator

type Creator struct {
	DCMESOptionalElement
}

type DCMESOptionalElement

type DCMESOptionalElement struct {
	Text string

	// Optional
	ID   ID
	Dir  TextDirection
	Lang XMLLang
	// contains filtered or unexported fields
}

DCMESOptionalElement is a template for several elements that are identical except for their names. This was the best solution I could come up with. See https://www.w3.org/publishing/epub3/epub-packages.html#sec-opf-dcmes-optional

func (DCMESOptionalElement) MarshalXML

func (element DCMESOptionalElement) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will not write a DCMESOptionalElement without any inner text.

func (*DCMESOptionalElement) UnmarshalXML

func (element *DCMESOptionalElement) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Date

type Date struct {
	T *time.Time
}

Date is a Marshal/Unmarshal wrapper around time.Time See https://www.w3.org/publishing/epub3/epub-packages.html#sec-opf-dcdate

func (*Date) MarshalXML

func (date *Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Date) UnmarshalXML

func (date *Date) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Description

type Description struct {
	DCMESOptionalElement
}

type Href

type Href string

func (Href) Name

func (Href) Name() string

Name gives the xml attribute name

func (Href) String

func (href Href) String() string

type ID

type ID string

ID is an identifier for the element. This will be referenced by other elements such as meta elements.

func (ID) Name

func (ID) Name() string

Name gives the xml attribute name

func (ID) String

func (id ID) String() string

type Identifier

type Identifier struct {
	// Required
	Text string

	//Optional
	ID ID
}

Identifier is some kind of identifier for the publication, for example a UUID or a publisher's id. If the identifier comes from an established system, an accompanying meta tag for the property "identifier-type" should be provided. See https://www.w3.org/publishing/epub3/epub-packages.html#sec-opf-dcidentifier

func (Identifier) MarshalXML

func (identifier Identifier) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will not write an identifier without any Text

func (*Identifier) UnmarshalXML

func (identifier *Identifier) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Language

type Language struct {
	// Required
	Text string

	// Optional
	ID ID
}

Language designates a language used in the publication. Metadata must contain at least one Language. Multiple languages may be specified in the case of multilingual publication, but the first Language is considered primary. Not that this does not specify the language of any child content. See https://www.w3.org/publishing/epub3/epub-packages.html#sec-opf-dclanguage

func (Language) MarshalXML

func (language Language) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will not write a language without any Text

func (*Language) UnmarshalXML

func (language *Language) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
type Link struct {
	// Required
	Href Href
	Rel  Rel

	// Required for external resources
	MediaType MediaType

	// Optional
	ID         ID
	Properties Properties
	Refines    Refines
}

Link represents a link to a resource either internally or externally. If the resource is external, MediaType must be populated. See https://www.w3.org/publishing/epub3/epub-packages.html#sec-link-elem

func (Link) MarshalXML

func (link Link) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML should write a self-closing tag, but the current xml implementation does not support it. It may look kind of ugly, but in theory it shouldn't be an issue unless a reader does not support the full xml spec.

func (*Link) UnmarshalXML

func (link *Link) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type MediaType

type MediaType string

func (MediaType) Name

func (MediaType) Name() string

Name gives the xml attribute name

func (MediaType) String

func (mediaType MediaType) String() string

type Meta

type Meta struct {
	// Required
	Text     string
	Property Property

	//Optional
	Refines       Refines
	Scheme        Scheme
	XMLLang       XMLLang
	TextDirection TextDirection
	ID            ID
}

Meta contains meta information See https://www.w3.org/publishing/epub3/epub-packages.html#sec-meta-elem

func (*Meta) MarshalXML

func (meta *Meta) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will not write out a meta element without any text

func (*Meta) UnmarshalXML

func (meta *Meta) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Metadata

type Metadata struct {
	XMLName     xml.Name
	Identifiers []Identifier
	Titles      []Title
	Languages   []Language
	Metas       []Meta

	//Optional
	Creators     []Creator
	Descriptions []Description
	Publishers   []Publisher
	Contributors []Contributor
	Coverages    []Coverage
	Relations    []Relation
	Rights       []Rights
	Subjects     []Subject
	Types        []Type
	Links        []Link
	Sources      []Source
	Date         Date
}

Metadata contains the metadata about the epub file See https://www.w3.org/publishing/epub3/epub-packages.html#sec-metadata-elem

func (Metadata) MarshalXML

func (metadata Metadata) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Metadata) UnmarshalXML

func (metadata *Metadata) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Package

type Package struct {
	XMLName xml.Name `xml:"package"`
	// Required
	Version          Version
	UniqueIdentifier UniqueIdentifier

	// Optional
	TextDirection TextDirection
	ID            ID
	Prefix        Prefix
	XMLLang       XMLLang

	Metadata Metadata
}

Package contains all the information about the epub See https://www.w3.org/publishing/epub3/epub-packages.html#sec-package-elem

func GetPackage

func GetPackage(zipFile *zip.Reader, path string) (*Package, error)

GetPackage retrieves the package from an epub file (which is a zip) and parses it using ParsePackage

func ParsePackage

func ParsePackage(file io.Reader) (*Package, error)

ParsePackage parses a package file into a Package.

func (Package) MarshalXML

func (pkg Package) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Package) UnmarshalXML

func (pkg *Package) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Prefix

type Prefix string

See https://www.w3.org/publishing/epub3/epub-packages.html#sec-prefix-attr

func (Prefix) Name

func (Prefix) Name() string

Name gives the xml attribute name

func (Prefix) String

func (prefix Prefix) String() string

type Properties

type Properties string

func (Properties) Name

func (Properties) Name() string

Name gives the xml attribute name

func (Properties) String

func (properties Properties) String() string

type Property

type Property string

Property is the property specified by the meta tag, for example "dcterms:modified" specifies the last modified date for the document.

func (Property) Name

func (Property) Name() string

Name gives the xml attribute name

func (Property) String

func (property Property) String() string

type Publisher

type Publisher struct {
	DCMESOptionalElement
}

type Refines

type Refines string

Refines links the meta tag to another element by specifying an element id in the format "#element-id"

func (Refines) Name

func (Refines) Name() string

Name gives the xml attribute name

func (Refines) String

func (refines Refines) String() string

type Rel

type Rel string

func (Rel) Name

func (Rel) Name() string

Name gives the xml attribute name

func (Rel) String

func (rel Rel) String() string

type Relation

type Relation struct {
	DCMESOptionalElement
}

type Rights

type Rights struct {
	DCMESOptionalElement
}

type Scheme

type Scheme string

Scheme identifies the scheme the value is drawn from

func (Scheme) Name

func (Scheme) Name() string

Name gives the xml attribute name

func (Scheme) String

func (scheme Scheme) String() string

type Source

type Source struct {
	DCMESOptionalElement
}

type Subject

type Subject struct {
	DCMESOptionalElement
}

type TextDirection

type TextDirection string

TextDirection annotates the direction of the text in the contained content and attributes

const (
	TextDirectionLTR TextDirection = `ltr`
	TextDirectionRTL TextDirection = `rtl`
)

func (TextDirection) Name

func (d TextDirection) Name() string

Name gives the xml attribute name

func (TextDirection) String

func (d TextDirection) String() string

type Title

type Title struct {
	// Required
	Text string

	// Optional
	ID   ID
	Dir  TextDirection
	Lang XMLLang
}

Title identifies a title of the document. At least one Title is required. If a title and subtitle are used, meta tags should identify which is which. The first Title is considered the primary title.

func (Title) MarshalXML

func (title Title) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML will not write a Title without any Text

func (*Title) UnmarshalXML

func (title *Title) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Type

type Type struct {
	DCMESOptionalElement
}

type UniqueIdentifier

type UniqueIdentifier string

UniqueIdentifier idenitifies the primary Identifier in the metadata

func (UniqueIdentifier) Name

func (UniqueIdentifier) Name() string

Name gives the xml attribute name

func (UniqueIdentifier) String

func (uid UniqueIdentifier) String() string

type Version

type Version string

Version contains the epub standard version

func (Version) Name

func (Version) Name() string

Name gives the xml attribute name

func (Version) String

func (version Version) String() string

type XMLLang

type XMLLang string

XMLLang specifies the language of the contents

func (XMLLang) Name

func (XMLLang) Name() string

Name gives the xml attribute name

func (XMLLang) String

func (lang XMLLang) String() string

Jump to

Keyboard shortcuts

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