Skip to content

Commit 4c7587b

Browse files
committed
Update formatting documentation for experimental formatter to default
Signed-off-by: Jessica He <jhe@redhat.com>
1 parent dfc0562 commit 4c7587b

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

docs/Formatting.md

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
## Formatting
22

3-
### xml.format.enabled
4-
5-
Set to `false` to disable XML formatting. Defaults to `true`.
6-
7-
***
8-
9-
### xml.format.experimental
10-
11-
Set to `true` to enable experimental formatter. Defaults to `false`.
3+
### Formatting strategy
124

13-
As the frequency of issues regarding the previous XML formatter increased, we have decided to redo our formatter from scratch. *Note*: this new formatter is flagged as experimental since it doesn't support all current formatter settings and uncaught bugs may occur. To enable this experimental formatter, the setting `xml.format.experimental` should be set to true.
5+
As the frequency of issues regarding the previous XML formatter increased, we have decided to redo our formatter from scratch. To revert to the old formatter, the setting `xml.format.legacy` should be set to true.
146

15-
We plan to have the experimental formatter replace the current formatter entirely once we have enough positive feedback and all current formatting settings are supported. To help with this, please don't hesitate to [create issues](https://github.com/redhat-developer/vscode-xml/issues) and give us feedback on this experimental formatter.
7+
The old formatter uses the DOM document to rewrite the XML document, or simply a fragment of XML (when range formatting is processed). *Note*: This strategy provides a lot of bugs if XML is not valid (ex : `<%` will format with `<null`).
168

17-
The current formatter uses the DOM document to rewrite the XML document, or simply a fragment of XML (when range formatting is processed). *Note*: This strategy provides a lot of bugs if XML is not valid (ex : `<%` will format with `<null`).
18-
19-
Any setting unsupported by the experimental formatter will be marked with **Not supported by the experimental formatter**, while settings exclusive to the experimental formatter will be marked with **This setting is only available with experimental formatter**.
20-
21-
The new strategy used by the experimental formatter formats the current XML by adding or removing some spaces without updating the XML content. The experimental formatter categorizes each element as:
9+
The new strategy used by the formatter formats the current XML by adding or removing some spaces without updating the XML content. The formatter categorizes each element as:
2210

2311
* `ignore space`
2412
* `normalize space`
@@ -46,34 +34,37 @@ Here `foo` is categorized as `ignore space`, because all children of `foo` are t
4634

4735
```xml
4836
<foo>
49-
abc
50-
def
37+
abc def
38+
ghi
5139
</foo>
5240
```
5341

54-
Here `foo` is categorized as `normalize space`, it means that it replaces all spaces with a single space. After formatting, you should see this result:
42+
Here `foo` is categorized as `normalize space` since it only contains text content, it means that it replaces all spaces on the same line with a single space while respecting existing line breaks. After formatting, you should see this result:
5543

5644
```xml
57-
<foo> abc def </foo>
45+
<foo>
46+
abc def
47+
ghi
48+
</foo>
5849
```
5950

6051
* `preserve space`
6152

62-
If you want to preserve space, you can use `xml:space="preserve"` to preserve spaces in some elements or use the [`xml.format.preserveSpace`](#xml.format.preserveSpace) setting.
53+
If you want to preserve space, you can use `xml:space="preserve"` to preserve spaces in some elements or use the [`xml.format.preserveSpace`](#xmlformatpreservespace) setting.
6354

6455
```xml
6556
<foo xml:space="preserve" >
66-
abc
67-
def
57+
abc
58+
def
6859
</foo>
6960
```
7061

7162
Here `foo` is categorized as `preserve space`. After formatting, you should see this result:
7263

7364
```xml
7465
<foo xml:space="preserve" >
75-
abc
76-
def
66+
abc
67+
def
7768
</foo>
7869
```
7970

@@ -87,7 +78,7 @@ Here `foo` is categorized as `preserve space`. After formatting, you should see
8778
</foo>
8879
```
8980

90-
Here `foo` is categorized as `mixed content`, since it contains text and tag element. All single spaces are removed. After formatting, you should see this result:
81+
Here `foo` is categorized as `mixed content`, since it contains text and tag element. All single spaces are removed between text content. After formatting, you should see this result:
9182

9283
```xml
9384
<foo>
@@ -96,6 +87,18 @@ Here `foo` is categorized as `mixed content`, since it contains text and tag ele
9687

9788
***
9889

90+
### xml.format.enabled
91+
92+
Set to `false` to disable XML formatting. Defaults to `true`.
93+
94+
***
95+
96+
### xml.format.legacy
97+
98+
Set to `true` to enable legacy formatter. Defaults to `false`.
99+
100+
Any setting unsupported by the legacy formatter will be marked with **Not supported by the legacy formatter**, while settings exclusive to the legacy formatter will be marked with **This setting is only available with legacy formatter**.
101+
99102
### xml.format.emptyElements
100103

101104
Expand/collapse empty elements. Available values are `ignore`, `collapse` and `expand`. Defaults to `ignore`.
@@ -181,6 +184,8 @@ The number of blank lines to leave between tags during formatting.
181184

182185
The default is 2. This means that if more than two consecutive empty lines are left in a document, then the number of blank lines will become 2.
183186

187+
Any number of new lines present that is less than the set number will also be preserved. In other words, if there is 1 new line between tags while `xml.format.preservedNewlines` is set to 2, the single new line will be preserved.
188+
184189
For example, this document:
185190
```xml
186191
<?xml version="1.0" encoding="UTF-8"?>
@@ -193,8 +198,6 @@ The default is 2. This means that if more than two consecutive empty lines are l
193198

194199
<child></child>
195200

196-
197-
198201
</root>
199202
```
200203

@@ -208,7 +211,6 @@ The default is 2. This means that if more than two consecutive empty lines are l
208211

209212
<child></child>
210213

211-
212214
</root>
213215
```
214216

@@ -284,6 +286,9 @@ If this value is set to 0, then all blank lines will be removed during formattin
284286
<project> </project>
285287
<a> </a>
286288
```
289+
290+
**This setting is only available with legacy formatter.**
291+
287292
***
288293

289294
### xml.format.joinCommentLines
@@ -398,7 +403,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes:
398403

399404
### files.trimFinalNewlines
400405

401-
Set to `true` to trim final newlines at the end of the document. Defaults to `false`
406+
Set to `true` to trim final newlines at the end of the document. This setting is overridden if `files.insertFinalNewline` is set to `true`. Defaults to `false`
402407
```xml
403408
<a><a/>
404409

@@ -589,13 +594,13 @@ Element names for which spaces will be preserved. Defaults is the following arra
589594
]
590595
```
591596

592-
**This setting is only available with experimental formatter.**
597+
**Not supported by the legacy formatter.**
593598

594599
### xml.format.maxLineWidth
595600

596601
Max line width. Set to `0` to disable this setting. Default is `0`.
597602

598-
**This setting is only available with experimental formatter.**
603+
**Not supported by the legacy formatter.**
599604

600605
### xml.format.grammarAwareFormatting
601606

@@ -627,4 +632,4 @@ After formatting, you should see that the content of `description` has spaces pr
627632

628633
The collapse option will now respect XSD's `nillable="false"` definitions. The collapse on the element will not be done if the element has `nillable="false"` in the XSD and `xsi:nil="true"` in the XML.
629634

630-
**This setting is only available with experimental formatter.**
635+
**Not supported by the legacy formatter.**

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,16 @@
302302
"markdownDescription": "Enforce `preferred` quote style (set by `#xml.preferences.quoteStyle#`) or `ignore` quote style when formatting. Default is `ignore`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatenforcequotestyle%22%7D%5D) for more information.",
303303
"scope": "window"
304304
},
305-
"xml.format.experimental": {
305+
"xml.format.legacy": {
306306
"type": "boolean",
307307
"default": false,
308-
"markdownDescription": "Enable/disable experimental formatter. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatexperimental%22%7D%5D) for more information.",
308+
"markdownDescription": "Enable/disable legacy formatter. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatlegacy%22%7D%5D) for more information.",
309309
"scope": "window"
310310
},
311311
"xml.format.grammarAwareFormatting": {
312312
"type": "boolean",
313313
"default": true,
314-
"markdownDescription": "Use Schema/DTD grammar information while formatting. Default is `true`. Supported only with experimental formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatgrammarawareformatting%22%7D%5D) for more information.",
314+
"markdownDescription": "Use Schema/DTD grammar information while formatting. Default is `true`. Not supported by legacy formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatgrammarawareformatting%22%7D%5D) for more information.",
315315
"scope": "window"
316316
},
317317
"xml.format.joinCDATALines": {
@@ -335,7 +335,7 @@
335335
"xml.format.maxLineWidth": {
336336
"type": "integer",
337337
"default": 0,
338-
"markdownDescription": "Max line width. Set to `0` to disable this setting. Default is `0`. Supported only with experimental formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatmaxlinewidth%22%7D%5D) for more information.",
338+
"markdownDescription": "Max line width. Set to `0` to disable this setting. Default is `0`. Not supported by legacy formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatmaxlinewidth%22%7D%5D) for more information.",
339339
"scope": "window"
340340
},
341341
"xml.format.preserveAttributeLineBreaks": {
@@ -347,7 +347,7 @@
347347
"xml.format.preserveEmptyContent": {
348348
"type": "boolean",
349349
"default": false,
350-
"markdownDescription": "Preserve empty content/whitespace in a tag. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreserveemptycontent%22%7D%5D) for more information.",
350+
"markdownDescription": "Preserve empty content/whitespace in a tag. Default is `false`. Supported only with legacy formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreserveemptycontent%22%7D%5D) for more information.",
351351
"scope": "window"
352352
},
353353
"xml.format.preservedNewlines": {
@@ -378,7 +378,7 @@
378378
"items": {
379379
"type": "string"
380380
},
381-
"markdownDescription": "Element names for which spaces will be preserved. Supported only with experimental formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreservespace%22%7D%5D) for more information.",
381+
"markdownDescription": "Element names for which spaces will be preserved. Not supported by legacy formatter. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatpreservespace%22%7D%5D) for more information.",
382382
"scope": "window"
383383
},
384384
"xml.format.spaceBeforeEmptyCloseTag": {
@@ -406,7 +406,7 @@
406406
"xml.format.splitAttributes": {
407407
"type": "boolean",
408408
"default": false,
409-
"markdownDescription": "Split multiple attributes each onto a new line. Default is `false`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributes%22%7D%5D) for more information.",
409+
"markdownDescription": "Split multiple attributes each onto a new line. Default is `false`. Indicate level of indentation with `#xml.format.splitAttributesIndentSize#`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatsplitattributes%22%7D%5D) for more information.",
410410
"scope": "window"
411411
},
412412
"xml.format.splitAttributesIndentSize": {

0 commit comments

Comments
 (0)