Skip to content

Commit

Permalink
Merge pull request #6 from blauer4/main
Browse files Browse the repository at this point in the history
Added support for custom CSS into EPUB
  • Loading branch information
gonejack authored Jul 22, 2024
2 parents a54362f + 724b3a8 commit cbfe7a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions html2epub/h2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (h *HtmlToEpub) makeBook() error {
h.book = epub.NewEpub(h.Title)
h.book.SetAuthor(h.Author)
h.book.SetDescription(fmt.Sprintf("Epub generated at %s with github.com/gonejack/html-to-epub", time.Now().Format("2006-01-02")))
if h.Css!="" {
h.book.AddCSS(h.Css, "custom_style.css")
}
return h.setCover()
}
func (h *HtmlToEpub) setCover() (err error) {
Expand Down Expand Up @@ -121,8 +124,13 @@ func (h *HtmlToEpub) add(index int, refs map[string]string, html string) (err er
if err != nil {
return
}

_, err = h.book.AddSection(content, title, "", "")

cssInternalPath := ""
if h.Css != "" {
cssInternalPath = "../css/custom_style.css"
}

_, err = h.book.AddSection(content, title, "", cssInternalPath)

return
}
Expand Down
3 changes: 2 additions & 1 deletion html2epub/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type Options struct {
Output string `short:"o" default:"output.epub" help:"Output filename."`
Verbose bool `short:"v" help:"Verbose printing."`
About bool `help:"About."`

Css string `default:"" help:"A path to a CSS stylesheet, local or online"`

ImagesDir string `hidden:"" default:"images"`

HTML []string `arg:"" optional:""`
Expand Down

0 comments on commit cbfe7a9

Please sign in to comment.