feat(html): whitespace-sensitive formatting#5168
Conversation
|
This is the result that we force-break multiline element: catalogs annually. We work out of three warehouses on the
<a
href="javascript:;"
onClick="MM_openBrWindow('/ogs/map_popup.php','FedcoMap','width=380,height=850')"
>Bellsqueeze and Hinckley Roads</a
>
in Clinton, Maine.I originally thought that we should move the text to the prev line: catalogs annually. We work out of three warehouses on the
<a
href="javascript:;"
onClick="MM_openBrWindow('/ogs/map_popup.php','FedcoMap','width=380,height=850')"
>Bellsqueeze and Hinckley Roads</a
> in Clinton, Maine.to align with the non-breakable one (in this case, the catalogs annually. We work out of three warehouses on the
<a
href="javascript:;"
onClick="MM_openBrWindow('/ogs/map_popup.php','FedcoMap','width=380,height=850')"
>Bellsqueeze and Hinckley Roads</a
>in Clinton, Maine.but then I found that if we do so it'll cause some inconsistent behavior for non-text elements that I don't think it looks better: catalogs annually. We work out of three warehouses on the
<input
some-long-long-long-long-long-long-long-long-long-long-long-long-long-attr
/> <input attr />so I think it's not a good idea to inline it (and actually the original output looks more readable to me). |
|
I understand this output is about the correctness of the code, but I don't think it's a good output to have. It's not as easy to read and to understand the intention as you may desire. |
|
@michaeljota That's why there's a |
|
@ikatyang Do you think we could have an option to prefer void tags over self-closing tags? 😃 |
|
Based on our Option Philosophy, we avoid adding options if possible, the |
|
I understand. Still, I'm going to say that there is enough people that prefer the usage of void elements over xml compatible self closing tags to at least have this as an option. |
|
@michaeljota Could you open a new issue for it? |
|
Sure. thanks! #5246. Thank you so much. |
|
I'll merge this PR tomorrow if there's no further comment. |
|
I still think that breaking the closing tag is a last resort and should be avoided as much as possible. IMHO the input looks better than the output in this example: Input: <p>
<b>Fuerit quovis est vacabo ac contineat aestimare ac contineat aestimare
pro</b>,
requiratur ii ut cognoscere concipitur.
</p>Output: <p>
<b
>Fuerit quovis est vacabo ac contineat aestimare ac contineat aestimare
pro</b
>, requiratur ii ut cognoscere concipitur.
</p>Also breaking the opening |
|
Commas and other punctuation probably should be a special case as this looks okay to me: <p>
<a
href="https://en.wikipedia.org/wiki/Balkans"
target="_blank"
class="link-to-wiki"
>balkan</a
>ization
</p>Better than: <p>
<a
href="https://en.wikipedia.org/wiki/Balkans"
target="_blank"
class="link-to-wiki"
>balkan</a>ization
</p> |
|
I play with that a little bit, and notice that if you set an space, then the tags won't weirdly break. I know that in most case, a leading and trailing space is not a big issue, but I wonder if in some cases this is could be undesirable. |
|
@thorn0 It seems it only happens with the specific print width, it looks okay if there're more or less text. Since it's a rare case, I think it should be fine to use the current behavior. <p>
<b>ac contineat aestimare pro</b>, requiratur ii ut cognoscere concipitur.
</p>
<p>
<b
>Fuerit quovis est vacabo ac contineat aestimare ac contineat aestimare
pro</b
>, requiratur ii ut cognoscere concipitur.
</p>
<p>
<b
>Fuerit quovis est vacabo ac contineat aestimare ac contineat Fuerit quovis
est vacabo ac contineat aestimare ac contineat Fuerit quovis est vacabo ac
contineat aestimare ac contineat aestimare pro</b
>, requiratur ii ut cognoscere concipitur.
</p> |
|
@michaeljota If you don't care about those leading/trailing spaces, you can always enable the |
|
No matter what print width is the opening |
|
Yeah, but it didn't look that weird comparing to the original one. And if we do so, the <p>
<b>
Fuerit quovis est vacabo ac contineat aestimare ac contineat aestimare
pro
</b>,
requiratur ii ut cognoscere concipitur.
</p>which is also not consistent with JSX: <p>
<b>
Fuerit quovis est vacabo ac contineat aestimare ac contineat aestimare
pro
</b>
, requiratur ii ut cognoscere concipitur.
</p>; |
This comment has been minimized.
This comment has been minimized.
|
As this looks acceptable in most cases so I'm going to merge this PR. Please open new issues for those special cases. |
display: block/white-space: pre(data fromhtml-styles)<!-- display: block -->)--html-whitespace-sensitivity <css|strict|ignore>)css: respect default css style (safe in the most cases)strict: every node is considered whitespace sensitive (the safest)ignore: every node is considered whitespace insensitive (dangerous, the current behavior)<!--[if IE]><![endif]-->)Prettier pr-5168 Playground link
docs/directory)