PR comments

This commit is contained in:
Bernard Xie 2022-11-21 13:24:10 -08:00
parent ab40e9a900
commit b99b741651
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
4 changed files with 8 additions and 9 deletions

View file

@ -2,8 +2,8 @@ For v0.0.99 we focused on X, Y and Z. Enjoy!
#### Features 💸 #### Features 💸
- Ability to export to PNG
- Now you can easily do x, y and z #9999 - Now you can easily do x, y and z #9999
- Ability to export to PNGs
#### Improvements 🔧 #### Improvements 🔧

View file

@ -133,12 +133,11 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
if err != nil { if err != nil {
return err return err
} }
defer func() error { defer func() {
err = pw.Cleanup() cleanupErr := pw.Cleanup()
if err != nil { if err == nil {
return err err = cleanupErr
} }
return nil
}() }()
} }

View file

@ -77,7 +77,7 @@ func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, erro
encodedSVG := base64.StdEncoding.EncodeToString(svg) encodedSVG := base64.StdEncoding.EncodeToString(svg)
pngInterface, err := page.Evaluate(genPNGScript, "data:image/svg+xml;charset=utf-8;base64,"+encodedSVG) pngInterface, err := page.Evaluate(genPNGScript, "data:image/svg+xml;charset=utf-8;base64,"+encodedSVG)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to generate png: %w\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", err) return nil, fmt.Errorf("failed to generate png: %w", err)
} }
pngString := pngInterface.(string) pngString := pngInterface.(string)
@ -85,7 +85,7 @@ func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, erro
if len(pngString) > 50 { if len(pngString) > 50 {
pngString = pngString[0:50] + "..." pngString = pngString[0:50] + "..."
} }
return nil, fmt.Errorf("invalid PNG: %q\nplease report this issue here: https://github.com/terrastruct/d2/issues/new", pngString) return nil, fmt.Errorf("invalid PNG: %q", pngString)
} }
splicedPNGString := pngString[len(pngPrefix):] splicedPNGString := pngString[len(pngPrefix):]
return base64.StdEncoding.DecodeString(splicedPNGString) return base64.StdEncoding.DecodeString(splicedPNGString)