Documentation
¶
Overview ¶
Package kepub provides conversion utilities for creating KePub files compatible with Kobo e-readers.
Index ¶
- Variables
- func IsImageFile(name string) bool
- func TransformContent(r io.Reader, w io.Writer) error
- func TransformContentBytes(input []byte) ([]byte, error)
- func TransformContentWithCounter(r io.Reader, w io.Writer, counter *SpanCounter) error
- func TransformContentWithOptions(r io.Reader, w io.Writer, counter *SpanCounter, scriptPath string) error
- func TransformOPF(r io.Reader, w io.Writer) error
- func TransformOPFBytes(input []byte) ([]byte, error)
- type CBZAuthor
- type CBZChapter
- type CBZMetadata
- type CBZSeries
- type Converter
- type ProcessedImage
- type SpanCounter
- type XHTMLProcessor
Constants ¶
This section is empty.
Variables ¶
var Palette16 = []uint8{
0x00, 0x11, 0x22, 0x33,
0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb,
0xcc, 0xdd, 0xee, 0xff,
}
Palette16 is the 16-level grayscale palette used by Kobo e-ink displays. This matches KCC (Kindle Comic Converter) for optimal e-ink rendering.
Functions ¶
func IsImageFile ¶ added in v0.0.8
IsImageFile returns true if the file extension indicates an image.
func TransformContent ¶
TransformContent transforms HTML/XHTML content for KePub compatibility. It adds Kobo span wrappers around text nodes and wrapper divs around body content. This creates a new span counter, so span IDs will start from kobo.1.1. For converting multiple files in one book, use TransformContentWithCounter instead.
func TransformContentBytes ¶
TransformContentBytes is a convenience function that transforms content from bytes.
func TransformContentWithCounter ¶
TransformContentWithCounter transforms content using the provided span counter. This allows maintaining unique span IDs across multiple files in a book. NOTE: Per Kobo's implementation, paragraph counters should be per-file, starting at 1.
func TransformContentWithOptions ¶
func TransformContentWithOptions(r io.Reader, w io.Writer, counter *SpanCounter, scriptPath string) error
TransformContentWithOptions transforms content with full control over options. The scriptPath parameter specifies the relative path to kobo.js from the content file. If empty, no script reference is added. This function preserves XHTML format by pre/post processing around html.Parse.
func TransformOPF ¶
TransformOPF transforms an OPF file for KePub compatibility. It ensures the cover image has the cover-image property set.
func TransformOPFBytes ¶
TransformOPFBytes is a convenience function that transforms OPF from bytes.
Types ¶
type CBZAuthor ¶
type CBZAuthor struct {
Name string
SortName string // e.g., "Doe, Jane" for sorting/file-as
Role string // writer, penciller, inker, etc.
}
CBZAuthor represents an author/creator for CBZ metadata.
type CBZChapter ¶
CBZChapter represents a chapter/section for CBZ metadata.
type CBZMetadata ¶
type CBZMetadata struct {
Title string
Name *string // Name takes precedence over Title when non-empty
Subtitle *string
Description *string
Authors []CBZAuthor
Series []CBZSeries
Genres []string
Tags []string
URL *string
Publisher *string
Imprint *string
ReleaseDate *time.Time
Chapters []CBZChapter
CoverPage *int // 0-indexed page number for cover (nil = first page)
}
CBZMetadata holds metadata for CBZ to KePub conversion.
type Converter ¶
type Converter struct {
// AddDummyTitlepage adds a dummy titlepage if needed for fullscreen covers.
AddDummyTitlepage bool
}
Converter handles EPUB to KePub conversion.
func NewConverter ¶
func NewConverter() *Converter
NewConverter creates a new Converter with default settings.
func (*Converter) ConvertCBZ ¶
ConvertCBZ converts a CBZ file to a fixed-layout KePub EPUB. JPEG/PNG images taller than 2000px are resized to 2000px height. PNG images are converted to JPEG for smaller file size.
func (*Converter) ConvertCBZWithMetadata ¶
func (c *Converter) ConvertCBZWithMetadata(ctx context.Context, srcPath, destPath string, metadata *CBZMetadata) error
ConvertCBZWithMetadata converts a CBZ file to a fixed-layout KePub EPUB with metadata. JPEG/PNG images taller than 2000px are resized to 2000px height. PNG images are converted to JPEG for smaller file size.
type ProcessedImage ¶ added in v0.0.8
ProcessedImage holds the result of image processing.
func ProcessImageForEreader ¶ added in v0.0.8
func ProcessImageForEreader(data []byte, origExt string) *ProcessedImage
ProcessImageForEreader resizes images to fit e-reader screen dimensions. - All JPEG/PNG images are resized to fit within Kobo Libra Color resolution (1264x1680) - Grayscale images (like manga) are converted to grayscale JPEG for faster rendering - PNG images are converted to JPEG for smaller file size - Other formats (GIF, WebP) are passed through unchanged.
type SpanCounter ¶
type SpanCounter struct {
// contains filtered or unexported fields
}
SpanCounter tracks span IDs for unique identification across content files. Use NewSpanCounter to create one, and pass the same counter to all content files in a book to ensure globally unique span IDs.
func NewSpanCounter ¶
func NewSpanCounter() *SpanCounter
NewSpanCounter creates a new span counter starting from 0.
type XHTMLProcessor ¶
type XHTMLProcessor struct {
// contains filtered or unexported fields
}
XHTMLProcessor handles conversion between XHTML and HTML5. Go's html package parses as HTML5, which mangles XHTML declarations. This processor preserves and restores XHTML-specific elements.
func NewXHTMLProcessor ¶
func NewXHTMLProcessor() *XHTMLProcessor
NewXHTMLProcessor creates a new XHTML processor.
func (*XHTMLProcessor) PostProcess ¶
func (p *XHTMLProcessor) PostProcess(content []byte) []byte
PostProcess converts HTML5 output back to XHTML format. Call this after html.Render to restore XHTML compliance.
func (*XHTMLProcessor) PreProcess ¶
func (p *XHTMLProcessor) PreProcess(content []byte) []byte
PreProcess extracts and removes the XML declaration from XHTML content. Call this before passing content to html.Parse.