In XML, only \t, \n, \r, and ` are considered [whitespace](https://www.w3.org/TR/xml/#NT-S) and are affected by the [xml:spaceattribute](https://www.w3.org/TR/xml/#sec-white-space). However, when formatting an XML document with thexmlWhitespaceSensitivityoption set toignore,@prettier/plugin-xmluses [String.prototype.trim()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) to remove whitespace characters, which results in removal of text that should be preserved.
Due to this behavior, formatting of documents containing elements that only have non-breaking spaces causes the output to be different depending on how many formatting runs are performed. Given this input:
In XML, only
\t
,\n
,\r
, and` are considered [whitespace](https://www.w3.org/TR/xml/#NT-S) and are affected by the [
xml:spaceattribute](https://www.w3.org/TR/xml/#sec-white-space). However, when formatting an XML document with the
xmlWhitespaceSensitivityoption set to
ignore,
@prettier/plugin-xmluses [
String.prototype.trim()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) to remove whitespace characters, which results in removal of text that should be preserved.https://github.com/prettier/plugin-xml/blob/68b3430186d6b9bfda86f683b97694492825bb3d/src/printer.js#L281-L288
For example, this document has a
<text>
element with 4 trailing U+00A0 No-Break Space characters:Formatting it removes these 4 trailing characters:
Due to this behavior, formatting of documents containing elements that only have non-breaking spaces causes the output to be different depending on how many formatting runs are performed. Given this input:
This is the output after formatting the input once:
And this is the output after formatting it twice:
Here's a list of affected characters:
And an XML document that has each of these characters repeated 4 times in separate
<text>
elements: