Documentation
¶
Overview ¶
epub.go generates EPUB 3 ebooks. The resulting .epub file is a ZIP archive containing XHTML, CSS, OPF metadata, and both EPUB 3 navigation and NCX files for wider reader compatibility.
Package output implements non-PDF output generators such as HTML and ePub.
output.go defines the shared output interfaces and registry. New output formats can be added through OutputFormat without changing the core build flow.
site.go generates a multi-page static site similar to GitBook. It includes sidebar navigation, previous/next links, search, and responsive layout.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChapterContent ¶
type ChapterContent struct {
// Title is the chapter title.
Title string
// ID is the unique chapter identifier.
ID string
// HTML is the chapter HTML without the outer document shell.
HTML string
// Filename is the suggested output filename, for example "ch_001.xhtml".
Filename string
}
ChapterContent stores rendered content for a single chapter.
type DocumentMeta ¶
DocumentMeta stores document metadata.
type EpubChapter ¶
type EpubChapter struct {
Title string
ID string
Filename string
HTML string // XHTML body content.
SourceDir string // Source directory used to resolve relative asset paths.
}
EpubChapter stores one EPUB chapter.
type EpubGenerator ¶
type EpubGenerator struct {
// contains filtered or unexported fields
}
EpubGenerator builds an EPUB file.
func NewEpubGenerator ¶
func NewEpubGenerator(meta EpubMeta) *EpubGenerator
NewEpubGenerator creates an ePub generator.
func (*EpubGenerator) AddChapter ¶
func (g *EpubGenerator) AddChapter(ch EpubChapter)
AddChapter appends a chapter.
func (*EpubGenerator) Generate ¶
func (g *EpubGenerator) Generate(outputPath string) error
Generate writes the EPUB file to disk.
func (*EpubGenerator) SetCSS ¶
func (g *EpubGenerator) SetCSS(css string)
SetCSS sets the global CSS.
type EpubMeta ¶
type EpubMeta struct {
Title string
Subtitle string
Author string
Language string
Version string
Description string
IncludeCover bool
CoverImagePath string
}
EpubMeta contains EPUB metadata.
type HTMLGenerator ¶
type HTMLGenerator struct{}
HTMLGenerator writes rendered HTML into a static site directory.
func NewHTMLGenerator ¶
func NewHTMLGenerator() *HTMLGenerator
NewHTMLGenerator creates an HTML generator.
type OutputFormat ¶
type OutputFormat interface {
// Name returns the format name, for example "pdf", "html", "epub", or "site".
Name() string
// Generate writes output using the provided render request.
Generate(ctx context.Context, req *RenderRequest, outputPath string) error
// Description returns a short human-readable description.
Description() string
}
OutputFormat is the shared interface implemented by each output backend.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores registered output formats.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an empty output format registry.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (OutputFormat, error)
Get returns an output format by name.
func (*Registry) Register ¶
func (r *Registry) Register(f OutputFormat)
Register adds or replaces an output format implementation.
type RenderRequest ¶
type RenderRequest struct {
// FullHTML is the assembled full HTML document for PDF and standalone HTML output.
FullHTML string
// Chapters contains per-chapter content for ePub and site output.
Chapters []ChapterContent
// CSS is the merged theme CSS and custom CSS.
CSS string
// Meta contains document metadata.
Meta DocumentMeta
}
RenderRequest contains all data needed to render any output format.
type SiteChapter ¶
type SiteChapter struct {
Title string
ID string
Filename string // Output HTML filename, for example "ch01.html".
Content string // Rendered HTML content.
Markdown string // Source markdown after variable expansion.
Depth int
Headings []SiteNavHeading
Children []SiteChapter
}
SiteChapter stores rendered chapter data for site output.
type SiteGenerator ¶
type SiteGenerator struct {
Meta SiteMeta
Chapters []SiteChapter
CSS string // Theme CSS plus custom CSS.
}
SiteGenerator generates the static site.
func NewSiteGenerator ¶
func NewSiteGenerator(meta SiteMeta) *SiteGenerator
NewSiteGenerator creates a site generator.
func (*SiteGenerator) AddChapter ¶
func (g *SiteGenerator) AddChapter(ch SiteChapter)
AddChapter appends a chapter.
func (*SiteGenerator) Generate ¶
func (g *SiteGenerator) Generate(outputDir string) error
Generate generates the static site pages, sitemap, and search index.
type SiteMeta ¶
type SiteMeta struct {
Title string
Subtitle string
Description string
Author string
Language string
Theme string // CSS theme name.
ThemeDescription string
}
SiteMeta stores site-wide metadata.
type SiteNavHeading ¶
type SiteNavHeading struct {
}
SiteNavHeading stores an in-chapter navigation tree.