remove empty board keywords

This commit is contained in:
Alexander Wang 2024-10-26 23:21:30 -06:00
parent efd401a2e1
commit 17846b4169
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
3 changed files with 22 additions and 3 deletions

View file

@ -7,6 +7,7 @@
- Lib: removes a dependency on external slog that was causing troubles with installation [#2137](https://github.com/terrastruct/d2/pull/2137)
- CLI: attempts writing to path atomically, falling back to non-atomic if failed [#2141](https://github.com/terrastruct/d2/pull/2141)
- Export: pptx has "created at" metadata removed, so successive runs yield the same result [#2169](https://github.com/terrastruct/d2/pull/2160)
- Formatter: empty board keywords (e.g. `layers`) are removed [#2178](https://github.com/terrastruct/d2/pull/2178)
#### Bugfixes ⛑️

View file

@ -293,11 +293,18 @@ func (p *printer) _map(m *d2ast.Map) {
if nb.IsBoardNode() {
switch nb.MapKey.Key.Path[0].Unbox().ScalarString() {
case "layers":
layerNodes = append(layerNodes, nb)
// remove useless
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
layerNodes = append(layerNodes, nb)
}
case "scenarios":
scenarioNodes = append(scenarioNodes, nb)
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
scenarioNodes = append(scenarioNodes, nb)
}
case "steps":
stepNodes = append(stepNodes, nb)
if nb.MapKey.Value.Map != nil && len(nb.MapKey.Value.Map.Nodes) > 0 {
stepNodes = append(stepNodes, nb)
}
}
prev = n
continue

View file

@ -881,6 +881,17 @@ coop: {
fill: blue
}
}
`,
},
{
name: "remove-empty-boards",
in: `k
layers
scenarios: {}
steps: asdf
`,
exp: `k
`,
},
}