Go library for creating EPUB files
| body | liber | |
| examples | fixes | |
| ident | liber | |
| internal | for performance | |
| lang | liber | |
| reftype | liber | |
| resource | liber | |
| .gitignore | Initial commit | |
| content.go | fixes | |
| content_test.go | fixes | |
| epub.go | fixes | |
| epub_test.go | fixes | |
| go.mod | upgrade nilo | |
| go.sum | upgrade nilo | |
| LICENSE | codeberg | |
| metadata.go | fixes | |
| metadata_test.go | fixes | |
| README.md | fixes | |
liber
Go library for creating EPUB files
Description
- Requires Go 1.26+
- This library provides a high-level, ergonomic API for creating EPUB files (2.0.1).
- It covers all epubcheck validations
Installation
go get -u codeberg.org/caskstrength/go-liber@latest
Example
packagemainimport("log""os""codeberg.org/caskstrength/go-liber""codeberg.org/caskstrength/go-liber/body""codeberg.org/caskstrength/go-liber/ident""codeberg.org/caskstrength/go-liber/lang""codeberg.org/caskstrength/go-liber/reftype""codeberg.org/caskstrength/go-liber/resource")funcmain(){f,err:=os.Create("book.epub")iferr!=nil{panic(err)}deferf.Close()e:=liber.EpubBuilder(liber.MetadataBuilder("My Book",lang.Spanish,ident.Default()).Creator("Johan Gambolputty").Build(),).Stylesheet(body.Raw("body {}")).CoverImage(resource.JpgFile("/path/cats.jpg")).AddResources(resource.PngFile("/path/cs.png")).AddContents(liber.ContentBuilder(body.Raw(`<body>
<h1>Chapter 1</h1>
<h2 id="id01">Section 1.1</h2>
<h2 id="id02">Section 1.1.1</h2>
<h2 id="id03">Section 1.2</h2>
</body>`,),reftype.Text("Chapter 1")).AddContentReferences(liber.ContentReferenceBuilder("Section 1.1").AddChildren(liber.ContentReferenceBuilder("Section 1.1.1").Build()).Build()).AddContentReferences(liber.ContentReferenceBuilder("Section 1.2").Build()).AddChildren(liber.ContentBuilder(body.Raw("<body><h1>Chapter 2</h1></body>"),reftype.Text("Chapter 2")).Build(),liber.ContentBuilder(body.Raw("<body><h1>Chapter 3</h1></body>"),reftype.Text("Chapter 3")).AddChildren(liber.ContentBuilder(body.Raw("<body><h1>Chapter 4</h1></body>"),reftype.Text("Chapter 4")).Build()).Build(),).Build(),).Build()iferr:=liber.Create(&e,f);err!=nil{os.Remove("book.epub")log.Fatal(err)}}Details
- Every content is a xhtml. The entire xhml text or only the body could be added as content (the latter is more practical and secure because follows the standard). See examples)
- Content (Ex: Chapter) and ContentReference (Ex: Chapter#ref1) could be named with filename and id methods respectively. If none is set, Content will be sequential c{number}.xhtml (c01.xhtml, c02.xhtml...) and ContentReferences will be id{number} (id01, id02...) corresponding to the Content.