question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't add space adjacent to html tags in some situations, even when ingonring whitespace sensitivity

See original GitHub issue

Prettier 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:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thorn0commented, Nov 13, 2018

So, Angular by default simply removes white-space-only text nodes: demo, src

This behavior can be changed by setting preserveWhitespaces to true:

  1. globally (app-wide), separately for JIT and AOT at that
  2. component-wide: pass preserveWhitespaces: true to the Component decorator
  3. element-wide, in the template: use the ngPreserveWhitespaces attribute

Now I see why Angular developers can have different expectations regarding white space formatting than the rest of those who write HTML.

0reactions
thorn0commented, Nov 13, 2018

Why not? Go ahead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How whitespace is handled by HTML, CSS, and in the DOM
First, all spaces and tabs immediately before and after a line break are ignored so, if we take our example markup from before:...
Read more >
css - Ignore whitespace in HTML - Stack Overflow
The problem with images (in this case) is that they are inline elements, so while you write them on separate lines, they are...
Read more >
When does white space matter in HTML? | by Patrick Brosset
White space is any string of text composed only of spaces, tabs or line breaks (to be precise, either CRLF sequences, carriage returns...
Read more >
WebD2: Common HTML Tags - University of Washington
Tags in HTML are not case sensitive, but in XHTML all tags must be in lower case. Even when coding in HTML, you...
Read more >
The CSS white-space Property Explained - Impressive Webs
(X)HTML also allows the use of the non-breaking space (   ). If you want to string together multiple spaces that you don't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found