2
0
Fork
You've already forked go-liber
0
Go library for creating EPUB files
  • Go 100%
Find a file
2026年06月20日 18:33:26 -03:00
body liber 2026年02月09日 10:58:54 -03:00
examples fixes 2026年04月22日 13:56:03 -03:00
ident liber 2026年02月09日 10:58:54 -03:00
internal for performance 2026年06月20日 18:33:26 -03:00
lang liber 2026年02月09日 10:58:54 -03:00
reftype liber 2026年02月09日 10:58:54 -03:00
resource liber 2026年02月09日 10:58:54 -03:00
.gitignore Initial commit 2026年01月17日 10:52:42 -03:00
content.go fixes 2026年04月22日 13:56:03 -03:00
content_test.go fixes 2026年04月22日 13:56:03 -03:00
epub.go fixes 2026年04月22日 13:56:03 -03:00
epub_test.go fixes 2026年04月22日 13:56:03 -03:00
go.mod upgrade nilo 2026年06月13日 18:39:13 -03:00
go.sum upgrade nilo 2026年06月13日 18:39:13 -03:00
LICENSE codeberg 2026年04月11日 12:06:30 -03:00
metadata.go fixes 2026年04月22日 13:56:03 -03:00
metadata_test.go fixes 2026年04月22日 13:56:03 -03:00
README.md fixes 2026年04月22日 13:56:03 -03:00

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.