fix(html): do not format non-normal whitespaces as normal whitespaces (#5797)

This commit is contained in:
Ika authored and GitHub committed 2019-01-30 14:30:10 +08:00
1 parent 1802ce1d9d
commit 847a78e8e9
4 files changed
+28 -4

No files matched your search

+20 -2
View File
@@ -47,5 +47,23 @@ Examples:
In Prettier 1.16.0 and 1.16.1, `--list-different` and `--check` logged every file in some CI environments, instead of just unformatted files.
This unwanted behavior is now fixed.
[#5804]: https://github.com/prettier/prettier/pull/5804
[@kachkaev]: https://github.com/kachkaev
- HTML: Do not format non-normal whitespace as normal whitespace ([#5797] by [@ikatyang])
Previously, only non-breaking whitespaces (U+00A0) are marked as non-normal whitespace,
which means other non-normal whitespaces such as non-breaking narrow whitespaces (U+202F)
could be formatted as normal whitespaces, which breaks the output. We now follow the spec to
exclude all non-[ASCII whitespace](https://infra.spec.whatwg.org/#ascii-whitespace) from whitespace normalization.
(`·` represents a non-breaking narrow whitespace)
<!-- prettier-ignore -->
```html
<!-- Input -->
Prix·:·32·€
<!-- Output (Prettier stable) -->
Prix : 32 €
<!-- Output (Prettier master) -->
Prix·:·32·€
```
+2 -2
View File
@@ -900,8 +900,8 @@ function getTextValueParts(node, value = node.value) {
dedentString(value.replace(/^\s*?\n|\n\s*?$/g, "")),
hardline
)
: // non-breaking whitespace: 0xA0
join(line, value.split(/[^\S\xA0]+/)).parts;
: // https://infra.spec.whatwg.org/#ascii-whitespace
join(line, value.split(/[\t\n\f\r ]+/)).parts;
}
function printEmbeddedAttributeValue(node, originalTextToDoc, options) {
@@ -203,6 +203,8 @@ printWidth: 80
<span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
<!-- non-breaking whitespaces -->
<span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
<!-- non-breaking narrow whitespaces -->
<span>Prix : 32 €</span>
=====================================output=====================================
<!-- normal whitespaces -->
@@ -214,6 +216,8 @@ printWidth: 80
<span
>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span
>
<!-- non-breaking narrow whitespaces -->
<span>Prix : 32 €</span>
================================================================================
`;
@@ -2,3 +2,5 @@
<span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
<!-- non-breaking whitespaces -->
<span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
<!-- non-breaking narrow whitespaces -->
<span>Prix : 32 €</span>