remove blankline in template rendering

This commit is contained in:
Celogeek 2023-01-16 08:45:01 +01:00
parent 21b099ab33
commit 6dc220d0f4
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
2 changed files with 9 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"image/color" "image/color"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@ -98,7 +99,9 @@ func (e *ePub) render(templateString string, data any) string {
panic(err) panic(err)
} }
return result.String() stripBlank := regexp.MustCompile("\n+")
return stripBlank.ReplaceAllString(result.String(), "\n")
} }
func (e *ePub) getParts() ([]*epubPart, error) { func (e *ePub) getParts() ([]*epubPart, error) {

View File

@ -69,6 +69,7 @@ type Option struct {
Auto bool Auto bool
AutoRotate bool AutoRotate bool
AutoSplitDoublePage bool AutoSplitDoublePage bool
NoBlankPage bool
Manga bool Manga bool
Workers int Workers int
LimitMb int LimitMb int
@ -103,6 +104,7 @@ Options:
Contrast : %d Contrast : %d
AutoRotate : %v AutoRotate : %v
AutoSplitDoublePage: %v AutoSplitDoublePage: %v
NoBlankPage : %v
Manga : %v Manga : %v
LimitMb : %s LimitMb : %s
Workers : %d Workers : %d
@ -118,6 +120,7 @@ Options:
o.Contrast, o.Contrast,
o.AutoRotate, o.AutoRotate,
o.AutoSplitDoublePage, o.AutoSplitDoublePage,
o.NoBlankPage,
o.Manga, o.Manga,
limitmb, limitmb,
o.Workers, o.Workers,
@ -149,6 +152,7 @@ func main() {
flag.BoolVar(&opt.Auto, "auto", false, "Activate all automatic options") flag.BoolVar(&opt.Auto, "auto", false, "Activate all automatic options")
flag.BoolVar(&opt.AutoRotate, "autorotate", false, "Auto Rotate page when width > height") flag.BoolVar(&opt.AutoRotate, "autorotate", false, "Auto Rotate page when width > height")
flag.BoolVar(&opt.AutoSplitDoublePage, "autosplitdoublepage", false, "Auto Split double page when width > height") flag.BoolVar(&opt.AutoSplitDoublePage, "autosplitdoublepage", false, "Auto Split double page when width > height")
flag.BoolVar(&opt.NoBlankPage, "noblankpage", false, "Remove blank pages")
flag.BoolVar(&opt.Manga, "manga", false, "Manga mode (right to left)") flag.BoolVar(&opt.Manga, "manga", false, "Manga mode (right to left)")
flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20") flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers") flag.IntVar(&opt.Workers, "workers", runtime.NumCPU(), "Number of workers")
@ -255,6 +259,7 @@ func main() {
Contrast: opt.Contrast, Contrast: opt.Contrast,
AutoRotate: opt.AutoRotate, AutoRotate: opt.AutoRotate,
AutoSplitDoublePage: opt.AutoSplitDoublePage, AutoSplitDoublePage: opt.AutoSplitDoublePage,
NoBlankPage: opt.NoBlankPage,
Manga: opt.Manga, Manga: opt.Manga,
Workers: opt.Workers, Workers: opt.Workers,
}, },