fix unmarshalling id with newlines from dagre

This commit is contained in:
Gavin Nishizawa 2022-12-05 11:13:19 -08:00
parent 21f531dff9
commit 8659af5d57
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -136,6 +136,9 @@ func Layout(ctx context.Context, g *d2graph.Graph) (err error) {
if err := json.Unmarshal([]byte(val.String()), &dn); err != nil { if err := json.Unmarshal([]byte(val.String()), &dn); err != nil {
return err return err
} }
// ID "ninety\nnine" is set in dagre with backticks: g.setNode(`"ninety\nnine"`, ...)
// but unmarshal converts \n into an actual newline, so we need to replace these to get the AbsID string and lookup the node
dn.ID = strings.ReplaceAll(dn.ID, "\n", "\\n")
if debugJS { if debugJS {
log.Debug(ctx, "graph", slog.F("json", dn)) log.Debug(ctx, "graph", slog.F("json", dn))
} }