Don't add space adjacent to html tags in some situations, even when ingonring whitespace sensitivity
See original GitHub issuePrettier 1.15.2 Playground link
# Options (if any):
--html-whitespace-sensitivity ignore
Input:
<span foo="bar" baz="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz">foo</span>.
Output:
<span foo="bar" baz="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz">
foo
</span>
.
Expected behavior:
<span foo="bar" baz="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz">
foo
</span>.
This may be related to #5449 and #5439, but I think it may be distinct. The basic issue here is that even when “ignoring” whitespace, I believe prettier shouldn’t be adding whitespace to the outer “edges” of elements. That means that adding whitespace on the inside “edge” of an element, say after <span>
or before </span>
, is OK, but adding whitespace just outside of an element can be an issue. As it is now, there is now way to both ignore whitespace on the inside edge of an element, but keep it on the outside.
I’d argue that adding the space before the period in this example is essentially equivalent to adding a space in the middle of a word–this is whitespace that will always be important.
This is particularly relevant for Angular users, which by default strips whitespace from code in most cases.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
So, Angular by default simply removes white-space-only text nodes: demo, src
This behavior can be changed by setting
preserveWhitespaces
to true:preserveWhitespaces: true
to theComponent
decoratorngPreserveWhitespaces
attributeNow I see why Angular developers can have different expectations regarding white space formatting than the rest of those who write HTML.
Why not? Go ahead.