You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Formatting.md
+38-33Lines changed: 38 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,12 @@
1
1
## Formatting
2
2
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
12
4
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.
14
6
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`).
16
8
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:
22
10
23
11
*`ignore space`
24
12
*`normalize space`
@@ -46,34 +34,37 @@ Here `foo` is categorized as `ignore space`, because all children of `foo` are t
46
34
47
35
```xml
48
36
<foo>
49
-
abc
50
-
def
37
+
abc def
38
+
ghi
51
39
</foo>
52
40
```
53
41
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:
55
43
56
44
```xml
57
-
<foo> abc def </foo>
45
+
<foo>
46
+
abc def
47
+
ghi
48
+
</foo>
58
49
```
59
50
60
51
*`preserve space`
61
52
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.
63
54
64
55
```xml
65
56
<fooxml:space="preserve" >
66
-
abc
67
-
def
57
+
abc
58
+
def
68
59
</foo>
69
60
```
70
61
71
62
Here `foo` is categorized as `preserve space`. After formatting, you should see this result:
72
63
73
64
```xml
74
65
<fooxml:space="preserve" >
75
-
abc
76
-
def
66
+
abc
67
+
def
77
68
</foo>
78
69
```
79
70
@@ -87,7 +78,7 @@ Here `foo` is categorized as `preserve space`. After formatting, you should see
87
78
</foo>
88
79
```
89
80
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:
91
82
92
83
```xml
93
84
<foo>
@@ -96,6 +87,18 @@ Here `foo` is categorized as `mixed content`, since it contains text and tag ele
96
87
97
88
***
98
89
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
+
99
102
### xml.format.emptyElements
100
103
101
104
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.
181
184
182
185
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.
183
186
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
+
184
189
For example, this document:
185
190
```xml
186
191
<?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
193
198
194
199
<child></child>
195
200
196
-
197
-
198
201
</root>
199
202
```
200
203
@@ -208,7 +211,6 @@ The default is 2. This means that if more than two consecutive empty lines are l
208
211
209
212
<child></child>
210
213
211
-
212
214
</root>
213
215
```
214
216
@@ -284,6 +286,9 @@ If this value is set to 0, then all blank lines will be removed during formattin
284
286
<project> </project>
285
287
<a> </a>
286
288
```
289
+
290
+
**This setting is only available with legacy formatter.**
291
+
287
292
***
288
293
289
294
### xml.format.joinCommentLines
@@ -398,7 +403,7 @@ If `xml.format.joinContentLines` is set to `true`, the above document becomes:
398
403
399
404
### files.trimFinalNewlines
400
405
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`
402
407
```xml
403
408
<a><a/>
404
409
@@ -589,13 +594,13 @@ Element names for which spaces will be preserved. Defaults is the following arra
589
594
]
590
595
```
591
596
592
-
**This setting is only available with experimental formatter.**
597
+
**Not supported by the legacy formatter.**
593
598
594
599
### xml.format.maxLineWidth
595
600
596
601
Max line width. Set to `0` to disable this setting. Default is `0`.
597
602
598
-
**This setting is only available with experimental formatter.**
603
+
**Not supported by the legacy formatter.**
599
604
600
605
### xml.format.grammarAwareFormatting
601
606
@@ -627,4 +632,4 @@ After formatting, you should see that the content of `description` has spaces pr
627
632
628
633
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.
629
634
630
-
**This setting is only available with experimental formatter.**
Copy file name to clipboardExpand all lines: package.json
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -302,16 +302,16 @@
302
302
"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.",
303
303
"scope": "window"
304
304
},
305
-
"xml.format.experimental": {
305
+
"xml.format.legacy": {
306
306
"type": "boolean",
307
307
"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.",
309
309
"scope": "window"
310
310
},
311
311
"xml.format.grammarAwareFormatting": {
312
312
"type": "boolean",
313
313
"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.",
315
315
"scope": "window"
316
316
},
317
317
"xml.format.joinCDATALines": {
@@ -335,7 +335,7 @@
335
335
"xml.format.maxLineWidth": {
336
336
"type": "integer",
337
337
"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.",
339
339
"scope": "window"
340
340
},
341
341
"xml.format.preserveAttributeLineBreaks": {
@@ -347,7 +347,7 @@
347
347
"xml.format.preserveEmptyContent": {
348
348
"type": "boolean",
349
349
"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.",
351
351
"scope": "window"
352
352
},
353
353
"xml.format.preservedNewlines": {
@@ -378,7 +378,7 @@
378
378
"items": {
379
379
"type": "string"
380
380
},
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.",
382
382
"scope": "window"
383
383
},
384
384
"xml.format.spaceBeforeEmptyCloseTag": {
@@ -406,7 +406,7 @@
406
406
"xml.format.splitAttributes": {
407
407
"type": "boolean",
408
408
"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.",
0 commit comments