diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 69969d43e4..e280a76f6f 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -14,6 +14,7 @@ - All font styles in sketch mode use a consistent font-family [#1463](https://github.com/terrastruct/d2/pull/1463) - Tooltip and link icons are now positioned on shape border [#1466](https://github.com/terrastruct/d2/pull/1466) - Tooltip and link icons are always rendered over shapes [#1467](https://github.com/terrastruct/d2/pull/1467) +- Ignores formatting on shebang comments[#1471](https://github.com/terrastruct/d2/pull/1471) #### Bugfixes ⛑️ diff --git a/d2format/format.go b/d2format/format.go index dc7430ec28..c9be8e1ad3 100644 --- a/d2format/format.go +++ b/d2format/format.go @@ -84,7 +84,8 @@ func (p *printer) comment(c *d2ast.Comment) { lines := strings.Split(c.Value, "\n") for i, line := range lines { p.sb.WriteString("#") - if line != "" { + isShebang := c.Range.Start.Line == 0 && c.Value[0] == '!' + if line != "" && !isShebang { p.sb.WriteByte(' ') } p.sb.WriteString(line) diff --git a/d2format/format_test.go b/d2format/format_test.go index 889b01537b..1fad8c65fa 100644 --- a/d2format/format_test.go +++ b/d2format/format_test.go @@ -810,6 +810,21 @@ steps: { step-1-content } } +`, + }, + { + name: "shebang", + in: `#!shebang +x -> y + +#!notShebang +#another comment + `, + exp: `#!shebang +x -> y + +# !notShebang +# another comment `, }, }