Documentation
¶
Index ¶
- Constants
- Variables
- type Book
- func (b *Book) AllChaptersText() string
- func (b *Book) AllMetadata() map[string][]string
- func (b *Book) ChapterByID(id string) (*Chapter, error)
- func (b *Book) ChapterByIndex(index int) (*Chapter, error)
- func (b *Book) ChapterCount() int
- func (b *Book) ChapterTextByID(id string) (string, error)
- func (b *Book) ChapterTextByIndex(index int) (string, error)
- func (b *Book) Contributor() (string, error)
- func (b *Book) Coverage() (string, error)
- func (b *Book) Creator() (string, error)
- func (b *Book) Date() (string, error)
- func (b *Book) Description() (string, error)
- func (b *Book) FlattenTOC() []TOC
- func (b *Book) Format() (string, error)
- func (b *Book) Identifier() (string, error)
- func (b *Book) Language() (string, error)
- func (b *Book) MetadataByKey(key string) ([]string, error)
- func (b *Book) MetadataValue(key string) (string, error)
- func (b *Book) MetadataValues(key string) ([]string, error)
- func (b *Book) Publisher() (string, error)
- func (b *Book) Relation() (string, error)
- func (b *Book) Rights() (string, error)
- func (b *Book) Source() (string, error)
- func (b *Book) Subject() (string, error)
- func (b *Book) Title() (string, error)
- func (b *Book) Type() (string, error)
- type Chapter
- type Container
- type EmptyXmlNode
- type HtmlNode
- type Manifest
- type MetaEntry
- type Metadata
- type NodeType
- type Opf
- type Spine
- type TOC
- type XmlNode
Constants ¶
const ( TOCTypeEPUB2 = "EPUB2" TOCTypeEPUB3 = "EPUB3" TOCTypeUnknown = "UNKNOWN" )
Variables ¶
var ( // ErrMetadataUndefined indicates that a requested metadata field is not // present in the document. ErrMetadataUndefined = errors.New("metadata not defined") // ErrChapterNotFound indicates that the requested chapter could not be // located either by ID or by index. ErrChapterNotFound = errors.New("chapter not found") )
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct {
Container *Container `json:"container,omitempty"`
Opf *Opf `json:"opf,omitempty"`
TOC *TOC `json:"toc,omitempty"`
Chapters []Chapter `json:"chapters,omitempty"`
}
func NewBook ¶
func NewBook() *Book
NewBook creates an empty book structure that can later be populated by the parser. The slices are initialised to avoid nil handling by callers.
func ReadBook ¶
ReadBook parses the EPUB file located at epubPath and populates a Book structure with metadata, table of contents and chapter information.
func (*Book) AllChaptersText ¶
AllChaptersText concatenates every chapter's text content in reading order.
func (*Book) AllMetadata ¶
AllMetadata returns all metadata entries, including extension fields defined in the OPF <meta> tags.
func (*Book) ChapterByID ¶
ChapterByID returns the chapter that matches the provided ID.
func (*Book) ChapterByIndex ¶
ChapterByIndex returns the chapter by its ordinal index (0-based).
func (*Book) ChapterCount ¶
ChapterCount returns the number of parsed chapters.
func (*Book) ChapterTextByID ¶
ChapterTextByID returns the joined text content of the chapter with the provided ID.
func (*Book) ChapterTextByIndex ¶
ChapterTextByIndex returns the joined text content of the chapter at the provided index.
func (*Book) Contributor ¶
func (*Book) Description ¶
func (*Book) FlattenTOC ¶
FlattenTOC returns the table of contents entries as a slice, skipping the synthetic root node if present.
func (*Book) Identifier ¶
func (*Book) MetadataByKey ¶
MetadataByKey provides direct access to Dublin Core metadata using a dynamic key. It is a convenience wrapper around MetadataValues and should be used by callers that need to iterate over keys.
func (*Book) MetadataValue ¶
MetadataValue returns the first value for the provided Dublin Core key.
func (*Book) MetadataValues ¶
MetadataValues returns all values for the given Dublin Core metadata key.
type Chapter ¶
func (*Chapter) Clone ¶
Clone returns a deep copy of the chapter. This is handy when callers want to modify the returned value without affecting the book cache.
type Container ¶
type Container struct {
Rootfiles []EmptyXmlNode
}
func ParseContainer ¶
ParseContainer parses the META-INF/container.xml document into a Container structure.
func (*Container) FindOpfFile ¶
type EmptyXmlNode ¶
func (EmptyXmlNode) Attr ¶
func (n EmptyXmlNode) Attr(name string) (string, bool)
Attr returns the attribute value for the provided name if it exists.
func (EmptyXmlNode) HasAttr ¶
func (n EmptyXmlNode) HasAttr(name string) bool
HasAttr reports whether the given attribute is defined on the node.
type HtmlNode ¶
type HtmlNode struct {
Type NodeType
Name string
Attrs map[string]string
Content string
Children []*HtmlNode
}
HtmlNode 是 HTML 版本的通用节点结构
type Manifest ¶
type Manifest struct {
Items []EmptyXmlNode
}
Manifest 对应 OPF manifest 区域 / Manifest models the OPF manifest section.
func (*Manifest) HrefLookup ¶
HrefLookup 构建 id->href 映射 / HrefLookup builds an id to href lookup map.
type MetaEntry ¶
type MetaEntry struct {
Value string // 文本内容 / Text content
Attrs map[string]string // 所有属性 / Attributes (refines, property, scheme, id, etc.)
}
MetaEntry 存储 metadata 元素 / MetaEntry stores metadata element values and attributes.
type Metadata ¶
Metadata 统一存储 namespace -> tag -> entries / Metadata maps namespaces and tags to entries.
type Opf ¶
func (*Opf) ChapterPaths ¶
ChapterPaths returns the ordered list of chapter document hrefs resolved against the OPF path.
func (*Opf) FindTOCFile ¶
func (*Opf) ParseManifest ¶
ParseManifest 解析 manifest 节点 / ParseManifest parses the manifest section of the OPF document.
func (*Opf) ParseMetadata ¶
ParseMetadata 解析 metadata 节点 / ParseMetadata extracts the metadata node from the OPF root.
func (*Opf) ParseSpine ¶
ParseSpine 解析 spine 节点 / ParseSpine parses the spine section of the OPF document.
type Spine ¶
type Spine struct {
Itemrefs []EmptyXmlNode
Attrs map[string]string
}
Spine 对应 OPF spine 区域 / Spine models the OPF spine section.
func (*Spine) ExtractChapterIDs ¶
ExtractChapterIDs 提取 spine 中的章节 ID / extractChapterIDs returns ordered chapter IDs from the spine.
type TOC ¶
func (TOC) FindByHref ¶
FindByHref returns the first TOC entry whose href matches the provided value. The comparison is performed after cleaning the href to make it resilient to small differences in path formatting.
type XmlNode ¶
type XmlNode struct {
XMLName xml.Name
Attrs []xml.Attr `xml:",any,attr"`
Content string `xml:",chardata"`
XmlNodes []XmlNode `xml:",any"`
}