From 7d8cbaa1fb096a7959a97a1ecd1a15fdff180541 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Mon, 26 Dec 2022 20:14:20 +0100 Subject: [PATCH] format output --- go.mod | 4 +- go.sum | 5 +- internal/epub/core.go | 6 +- internal/epub/templates/style.css.tmpl | 107 ++++++++++++++----------- 4 files changed, 67 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index 329e1ea..5cdd2a8 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.19 require ( github.com/bmaupin/go-epub v1.0.1 + github.com/gofrs/uuid v3.1.0+incompatible github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 + github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 golang.org/x/image v0.2.0 - golang.org/x/mod v0.7.0 ) require ( github.com/gabriel-vasile/mimetype v1.3.1 // indirect - github.com/gofrs/uuid v3.1.0+incompatible // indirect golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect ) diff --git a/go.sum b/go.sum index 969485f..9e97cbc 100644 --- a/go.sum +++ b/go.sum @@ -6,15 +6,14 @@ github.com/gofrs/uuid v3.1.0+incompatible h1:q2rtkjaKT4YEr6E1kamy0Ha4RtepWlQBedy github.com/gofrs/uuid v3.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50 h1:uxE3GYdXIOfhMv3unJKETJEhw78gvzuQqRX/rVirc2A= github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U= +github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 h1:0sw0nJM544SpsihWx1bkXdYLQDlzRflMgFJQ4Yih9ts= +github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/image v0.2.0 h1:/DcQ0w3VHKCC5p0/P2B0JpAZ9Z++V2KOo2fyU89CXBQ= golang.org/x/image v0.2.0/go.mod h1:la7oBXb9w3YFjBqaAwtynVioc1ZvOnNteUNrifGNmAI= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= -golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= diff --git a/internal/epub/core.go b/internal/epub/core.go index 70e42fc..951c914 100644 --- a/internal/epub/core.go +++ b/internal/epub/core.go @@ -12,6 +12,7 @@ import ( "time" "github.com/gofrs/uuid" + "github.com/yosssi/gohtml" ) type Images struct { @@ -102,7 +103,8 @@ func (e *EPub) Render(templateString string, data any) string { if err := tmpl.Execute(result, data); err != nil { panic(err) } - return result.String() + + return gohtml.Format(result.String()) } func (e *EPub) LoadDir(dirname string) *EPub { @@ -155,7 +157,7 @@ func (e *EPub) Write() error { zipContent := [][]string{ {"mimetype", TEMPLATE_MIME_TYPE}, - {"META-INF/container.xml", TEMPLATE_CONTAINER}, + {"META-INF/container.xml", gohtml.Format(TEMPLATE_CONTAINER)}, {"OEBPS/content.opf", e.Render(TEMPLATE_CONTENT, e)}, {"OEBPS/toc.ncx", e.Render(TEMPLATE_TOC, e)}, {"OEBPS/nav.xhtml", e.Render(TEMPLATE_NAV, e)}, diff --git a/internal/epub/templates/style.css.tmpl b/internal/epub/templates/style.css.tmpl index b8d765a..07eb2ce 100644 --- a/internal/epub/templates/style.css.tmpl +++ b/internal/epub/templates/style.css.tmpl @@ -1,72 +1,83 @@ @page { -margin: 0; + margin: 0; } + body { -display: block; -margin: 0; -padding: 0; + display: block; + margin: 0; + padding: 0; } + #PV { -position: absolute; -width: 100%; -height: 100%; -top: 0; -left: 0; + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; } + #PV-T { -top: 0; -width: 100%; -height: 50%; + top: 0; + width: 100%; + height: 50%; } + #PV-B { -bottom: 0; -width: 100%; -height: 50%; + bottom: 0; + width: 100%; + height: 50%; } + #PV-L { -left: 0; -width: 49.5%; -height: 100%; -float: left; + left: 0; + width: 49.5%; + height: 100%; + float: left; } + #PV-R { -right: 0; -width: 49.5%; -height: 100%; -float: right; + right: 0; + width: 49.5%; + height: 100%; + float: right; } + #PV-TL { -top: 0; -left: 0; -width: 49.5%; -height: 50%; -float: left; + top: 0; + left: 0; + width: 49.5%; + height: 50%; + float: left; } + #PV-TR { -top: 0; -right: 0; -width: 49.5%; -height: 50%; -float: right; + top: 0; + right: 0; + width: 49.5%; + height: 50%; + float: right; } + #PV-BL { -bottom: 0; -left: 0; -width: 49.5%; -height: 50%; -float: left; + bottom: 0; + left: 0; + width: 49.5%; + height: 50%; + float: left; } + #PV-BR { -bottom: 0; -right: 0; -width: 49.5%; -height: 50%; -float: right; + bottom: 0; + right: 0; + width: 49.5%; + height: 50%; + float: right; } + .PV-P { -width: 100%; -height: 100%; -top: 0; -position: absolute; -display: none; + width: 100%; + height: 100%; + top: 0; + position: absolute; + display: none; } \ No newline at end of file