fix watch mode for pdf gen

This commit is contained in:
Bernard Xie 2023-02-14 17:39:59 -08:00
parent 890a7d8b2c
commit 31fdaad555
No known key found for this signature in database
GPG key ID: 3C3E0036CE0F892C
2 changed files with 3 additions and 5 deletions

View file

@ -356,7 +356,7 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc
return svg, nil
}
func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketch bool, pad int64, outputPath string, page playwright.Page, ruler *textmeasure.Ruler, diagram *d2target.Diagram, pdf *pdflib.GoFPDF, boardPath []string, isScenario bool) ([]byte, error) {
func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketch bool, pad int64, outputPath string, page playwright.Page, ruler *textmeasure.Ruler, diagram *d2target.Diagram, pdf *pdflib.GoFPDF, boardPath []string, isScenario bool) (svg []byte, err error) {
var isRoot bool
if pdf == nil {
pdf = pdflib.Init()
@ -375,9 +375,8 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
currBoardPath = append(boardPath, diagram.Name)
}
var svg []byte
if !isScenario {
svg, err := d2svg.Render(diagram, &d2svg.RenderOpts{
svg, err = d2svg.Render(diagram, &d2svg.RenderOpts{
Pad: int(pad),
Sketch: sketch,
})
@ -407,7 +406,6 @@ func renderPDF(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, ske
if err != nil {
return svg, err
}
}
for _, dl := range diagram.Layers {

View file

@ -344,7 +344,7 @@ func (w *watcher) compileLoop(ctx context.Context) error {
recompiledPrefix = "re"
}
if filepath.Ext(w.outputPath) == ".png" && !w.pw.Browser.IsConnected() {
if (filepath.Ext(w.outputPath) == ".png" || filepath.Ext(w.outputPath) == ".pdf") && !w.pw.Browser.IsConnected() {
newPW, err := w.pw.RestartBrowser()
if err != nil {
broadcastErr := fmt.Errorf("issue encountered with PNG exporter: %w", err)