diff --git a/.changeset/smart-bats-attack.md b/.changeset/smart-bats-attack.md new file mode 100644 index 0000000..d588541 --- /dev/null +++ b/.changeset/smart-bats-attack.md @@ -0,0 +1,5 @@ +--- +'prettier-plugin-astro': patch +--- + +Fix `
` tags sometimes causing additional spaces to appear diff --git a/src/printer/index.ts b/src/printer/index.ts index 0935c78..9e6e928 100644 --- a/src/printer/index.ts +++ b/src/printer/index.ts @@ -351,7 +351,7 @@ function splitTextToDocs(node: TextNode): Doc[] { const textLines = text.split(/[\t\n\f\r ]+/); - let docs = join(line, textLines); + let docs = join(line, textLines).filter((doc) => doc !== ''); if (startsWithLinebreak(text)) { docs[0] = hardline; diff --git a/test/fixtures/other/clean-self-closing/input.astro b/test/fixtures/other/clean-self-closing/input.astro new file mode 100644 index 0000000..8c1a038 --- /dev/null +++ b/test/fixtures/other/clean-self-closing/input.astro @@ -0,0 +1,8 @@ +

+ test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test test + test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test +

diff --git a/test/fixtures/other/clean-self-closing/output.astro b/test/fixtures/other/clean-self-closing/output.astro new file mode 100644 index 0000000..020b238 --- /dev/null +++ b/test/fixtures/other/clean-self-closing/output.astro @@ -0,0 +1,8 @@ +

+ test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test
+ test test test test test test test test test test test test test test test test + test test test test test test test test test test test test
+ test test test test test test test test test test test test test test +

diff --git a/test/tests/other.test.ts b/test/tests/other.test.ts index de8aca7..eacb641 100644 --- a/test/tests/other.test.ts +++ b/test/tests/other.test.ts @@ -81,6 +81,8 @@ test('Can format nested comment', files, 'other/nested-comment'); test('Format binary expressions', files, 'other/binary-expression'); +test('Format self-closing tags without additional content', files, 'other/clean-self-closing'); + test('Format directives', files, 'other/directive'); test('Format slots', files, 'other/slots');