Skip to content

Commit

Permalink
fix: regression with self-closing tags text (#394)
Browse files Browse the repository at this point in the history
* fix: regression with self-closing tags text

* chore: changeset
  • Loading branch information
Princesseuh authored Dec 26, 2023
1 parent b4b0918 commit e75f9c7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smart-bats-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-astro': patch
---

Fix `<br />` tags sometimes causing additional spaces to appear
2 changes: 1 addition & 1 deletion src/printer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/other/clean-self-closing/input.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
<b>test test test</b><br />
test test test test test test test test test test test test test test<br />
test test test test test test test test test test test test test test<br />
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<br />
test test test test test test test test test test test test test test
</p>
8 changes: 8 additions & 0 deletions test/fixtures/other/clean-self-closing/output.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
<b>test test test</b><br />
test test test test test test test test test test test test test test<br />
test test test test test test test test test test test test test test<br />
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<br />
test test test test test test test test test test test test test test
</p>
2 changes: 2 additions & 0 deletions test/tests/other.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit e75f9c7

Please sign in to comment.