Skip to content

Commit d918675

Browse files
authored
(fix) ignore whitespace sensitivity with Svelte components (#281) (#282)
Fixes #281
1 parent fa742ba commit d918675

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# prettier-plugin-svelte changelog
22

3+
## 2.6.1 (Unreleased)
4+
5+
* (fix) respect whitespace "ignore" setting for components ([#281](https://github.com/sveltejs/prettier-plugin-svelte/issues/281))
6+
37
## 2.6.0
48

59
* (feat) Support `{@const}` tag ([#272](https://github.com/sveltejs/prettier-plugin-svelte/issues/272))

src/print/node-helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ export function shouldHugStart(
396396
return true;
397397
}
398398

399+
if (options.htmlWhitespaceSensitivity === 'ignore') {
400+
return false;
401+
}
402+
399403
const firstChild = children[0];
400404
return !isTextNodeStartingWithWhitespace(firstChild);
401405
}
@@ -426,6 +430,10 @@ export function shouldHugEnd(
426430
return true;
427431
}
428432

433+
if (options.htmlWhitespaceSensitivity === 'ignore') {
434+
return false;
435+
}
436+
429437
const lastChild = children[children.length - 1];
430438
return !isTextNodeEndingWithWhitespace(lastChild);
431439
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p><ExternalLink href="https://www.buymeacoffee.com">buy</ExternalLink>!</p>
2+
3+
<p><ExternalLink href="https://www.buymeacoffee.com">buy me a</ExternalLink>!</p>
4+
5+
<p><ExternalLink href="https://www.buymeacoffee.com">buy me a coffee</ExternalLink>!</p>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"htmlWhitespaceSensitivity": "ignore"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<p><ExternalLink href="https://www.buymeacoffee.com">buy</ExternalLink>!</p>
2+
3+
<p>
4+
<ExternalLink href="https://www.buymeacoffee.com">buy me a</ExternalLink>!
5+
</p>
6+
7+
<p>
8+
<ExternalLink href="https://www.buymeacoffee.com">
9+
buy me a coffee
10+
</ExternalLink>!
11+
</p>

0 commit comments

Comments
 (0)