Documentation
¶
Overview ¶
Package epub writes HTML presentation documents as EPUB 3 publications.
EPUB (Electronic Publication) is an open e-book format built on web standards. An EPUB is a ZIP archive that contains publication metadata, navigation, and XHTML content documents that readers can reflow for different screens. Commonly supported HTML tags include a, article, aside, blockquote, br, code, div, em, figure, h1-h6, hr, img, li, ol, p, pre, section, span, strong, table, and ul.
## Considerations
- <https://willcrichton.net/notes/portable-epubs/#epub-content%2FEPUB%2Findex.xhtml$>
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(ctx context.Context, w io.Writer, source []byte, node ast.Node, withOptions ...Option) error
New renders a parsed Markdown AST as EPUB 3 and writes the archive to w. source must be the byte slice used to parse node with mdcoach.NewParser.
func NewSources ¶
func NewSources( ctx context.Context, w io.Writer, sources []presentation.Source, withOptions ...Option, ) error
NewSources renders parsed Markdown sources together into one EPUB 3 archive. Each source should be parsed with mdcoach.NewParser; source paths are used to resolve relative images unless media options provide a filesystem or path.
Types ¶
type ImageCache ¶
type ImageCache struct {
// contains filtered or unexported fields
}
ImageCache stores PNG images by source location and content hash.
func NewImageCache ¶
func NewImageCache() *ImageCache
NewImageCache creates an empty, concurrency-safe image cache.
func (*ImageCache) Get ¶
func (c *ImageCache) Get(location string) (*Image, bool)
Get returns the cached image at location, if present.
func (*ImageCache) Set ¶
func (c *ImageCache) Set(image *Image)
Set adds image to the cache by its content hash and source location.
type ImageLoader ¶
type ImageLoader struct {
// contains filtered or unexported fields
}
ImageLoader loads, resizes, and caches images as PNG files.
func NewImageLoader ¶
func NewImageLoader(cache *ImageCache, options MediaOptions) *ImageLoader
NewImageLoader creates a loader that caches PNG images.
func (*ImageLoader) LoadImages ¶
LoadImages downloads image destinations owned by nodes in the Markdown AST.
type MediaOptions ¶
type MediaOptions struct {
FS fs.FS
Path string
WidthLimit int
HeightLimit int
HTTPClient *http.Client
}
MediaOptions configures an ImageLoader's filesystem and output dimensions.
type Option ¶
type Option func(*newOptions) error
Option configures AST-to-EPUB rendering.
func WithEmoteFS ¶
WithEmoteFS sets the filesystem used to resolve emote PNGs.
func WithMediaOptions ¶
func WithMediaOptions(media MediaOptions) Option
WithMediaOptions configures local and remote image loading.
func WithMetadata ¶
func WithMetadata(metadata presentation.Frontmatter) Option
WithMetadata sets the EPUB publication metadata.