epub

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2022 License: MIT Imports: 20 Imported by: 1

README

License


The goal of this fork is to make generation of novel epubs simple.

This is not a general purpose epub library, go to bmaupin/go-epub for that. If you want an epub library that can pull in markdown files and push out novels with chapters and automatically generated tables of contents, then this may be what you're looking for.

Features

  • Forked from github.com/bmaupin/go-epub, but nearly completely rewritten
  • Customizable templates for all the epub files
  • Create chapters using Markdown or HTML
  • Book-focused stylesheet
  • Add an entire Images Folder instead of individual files

For an example of actual usage, see https://github.com/cahaba-ts/cahaba

Contributions

I'm not interested in generalizing the library in a way that complicates the novel workflow. Tweaks to the css file or fixes for bugs in specific epub applications would be helpful.

Development

Clone this repository using Git, it requires Go version 1.18 or higher.

Dependencies are managed using Go modules

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug = false
View Source
var ImageMediaTypes = map[string]string{
	".png":  "image/png",
	".jpg":  "image/jpeg",
	".jpeg": "image/jpeg",
	".svg":  "image/svg+xml",
	".webp": "image/webp",
	".jxl":  "image/jxl",
	".gif":  "image/gif",
	".heif": "image/heif",
	".avif": "image/avif",
}

Functions

func CompileTemplate added in v1.0.0

func CompileTemplate(filename string) (*template.Template, error)

func OverrideTemplate added in v1.0.0

func OverrideTemplate(filename string, content []byte)

OverrideTemplate will set a new template for the filename. Valid filenames are book.opf, chapter.xhtml, container.xml, cover.xhtml, main.css, toc.ncx, and toc.xhtml.

func RegisterShortcode added in v1.0.0

func RegisterShortcode(name string, handler ShortcodeHandler)

func RetrieveTemplate added in v1.0.0

func RetrieveTemplate(filename string) ([]byte, error)

RetrieveTemplate returns either the default template or an overridden template for the filename

Types

type Book added in v1.0.0

type Book struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Epub implements an EPUB file.

func NewBook added in v1.0.0

func NewBook(title string) *Book

NewBook returns a new Epub.

func (*Book) AddAsset added in v1.0.0

func (e *Book) AddAsset(source, filename, mediaType string) error

func (*Book) AddChapterHTML added in v1.0.0

func (e *Book) AddChapterHTML(title string, body []string) error

func (*Book) AddChapterMD added in v1.0.0

func (e *Book) AddChapterMD(title, body string) error

func (*Book) AddImage added in v1.0.0

func (e *Book) AddImage(source, filename string) error

func (*Book) AddImageFolder added in v1.0.0

func (e *Book) AddImageFolder(source string) error

func (*Book) AddIntroductionHTML added in v1.0.0

func (e *Book) AddIntroductionHTML(title string, body []string) error

func (*Book) AddIntroductionMD added in v1.0.0

func (e *Book) AddIntroductionMD(title string, body string) error

func (*Book) AddMDExtension added in v1.0.0

func (e *Book) AddMDExtension(ext goldmark.Extender)

AddMDExtension adds another extension to goldmark. Note that the Table, Strikethrough, and Definition List extensions are already added.

func (*Book) AddPostscriptHTML added in v1.0.0

func (e *Book) AddPostscriptHTML(title string, body []string) error

func (*Book) AddPostscriptMD added in v1.0.0

func (e *Book) AddPostscriptMD(title, body string) error

func (*Book) Author added in v1.0.0

func (e *Book) Author() string

func (*Book) Description added in v1.0.0

func (e *Book) Description() string

func (*Book) Identifier added in v1.0.0

func (e *Book) Identifier() string

func (*Book) LookupAsset added in v1.0.0

func (e *Book) LookupAsset(assetFilename string) (string, bool)

func (*Book) LookupImage added in v1.0.0

func (e *Book) LookupImage(imageFilename string) (string, bool)

func (*Book) Publisher added in v1.0.0

func (e *Book) Publisher() string

func (*Book) ReleaseDate added in v1.0.0

func (e *Book) ReleaseDate() string

func (*Book) SetAuthor added in v1.0.0

func (e *Book) SetAuthor(author string)

func (*Book) SetCSS added in v1.0.0

func (e *Book) SetCSS(source string) error

SetCSS will set the CSS file for the book. It is not recommended to call this more than once for a book.

func (*Book) SetCover added in v1.0.0

func (e *Book) SetCover(source string) error

func (*Book) SetDescription added in v1.0.0

func (e *Book) SetDescription(d string)

func (*Book) SetIdentifier added in v1.0.0

func (e *Book) SetIdentifier(id string)

func (*Book) SetPublisher added in v1.0.0

func (e *Book) SetPublisher(pub string)

func (*Book) SetReleaseDate added in v1.0.0

func (e *Book) SetReleaseDate(t string)

func (*Book) SetTitle added in v1.0.0

func (e *Book) SetTitle(t string)

func (*Book) Title added in v1.0.0

func (e *Book) Title() string

func (*Book) Write added in v1.0.0

func (e *Book) Write(filename string) error

type FileRetrievalError added in v0.4.0

type FileRetrievalError struct {
	Source string // The source of the file whose retrieval failed
	Err    error  // The underlying error that was thrown
}

FileRetrievalError is thrown by AddCSS, AddFont, AddImage, or Write if there was a problem retrieving the source file that was provided.

func (*FileRetrievalError) Error added in v0.4.0

func (e *FileRetrievalError) Error() string

type FilenameAlreadyUsedError added in v0.4.0

type FilenameAlreadyUsedError struct {
	Filename string // Filename that caused the error
}

FilenameAlreadyUsedError is thrown by AddCSS, AddFont, AddImage, or AddSection if the same filename is used more than once.

func (*FilenameAlreadyUsedError) Error added in v0.4.0

func (e *FilenameAlreadyUsedError) Error() string

type ShortcodeHandler added in v1.0.0

type ShortcodeHandler func(*Book, string, map[string]any, string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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