Skip to content

Commit 63101e9

Browse files
committed
Add new formatting setting xml.format.numberOfIndentsForSplitAttributes
Add a new setting which controls the level of indentation of attributes with respect to their parent element when `xml.format.splitAttributes` is set to `true`. Based off of a comment by Cong Wang (@I322871) on the vscode-xml Gitter Signed-off-by: David Thompson <davthomp@redhat.com>
1 parent 20f8e75 commit 63101e9

File tree

3 files changed

+88
-46
lines changed

3 files changed

+88
-46
lines changed

docs/Formatting.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ If this value is set to 0, then all blank lines will be removed during formattin
148148
### xml.format.splitAttributes
149149

150150
Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`.
151-
Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks)
151+
Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](#xmlformatpreserveattributelinebreaks).
152+
Please see [xml.format.numberOfIndentsForSplitAttributes](#xmlformatnumberOfIndentsForSplitAttributes) for information on configuring the indentation level of the attributes.
152153

153154
```xml
154155
<project a="1" b="2" c="3"></project>
@@ -332,4 +333,66 @@ If it is set to `true`, the above document becomes:
332333
```
333334

334335
***
336+
### xml.format.numberOfIndentsForSplitAttributes
335337

338+
Use to configure how many levels to indent the attributes by when `xml.format.splitAttributes` is set to `true`.
339+
340+
Here are some examples. For these examples, an indentation is two spaces.
341+
342+
`xml.format.numberOfIndentsForSplitAttributes = 2` (default)
343+
344+
```xml
345+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
346+
<child />
347+
<child />
348+
</robot>
349+
```
350+
becomes
351+
```xml
352+
<robot
353+
attribute1="value1"
354+
attribute2="value2"
355+
attribute3="value3">
356+
<child />
357+
<child />
358+
</robot>
359+
```
360+
361+
`xml.format.numberOfIndentsForSplitAttributes = 1`
362+
363+
```xml
364+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
365+
<child />
366+
<child />
367+
</robot>
368+
```
369+
becomes
370+
```xml
371+
<robot
372+
attribute1="value1"
373+
attribute2="value2"
374+
attribute3="value3">
375+
<child />
376+
<child />
377+
</robot>
378+
```
379+
380+
`xml.format.numberOfIndentsForSplitAttributes = 3`
381+
382+
```xml
383+
<robot attribute1="value1" attribute2="value2" attribute3="value3">
384+
<child />
385+
<child />
386+
</robot>
387+
```
388+
becomes
389+
```xml
390+
<robot
391+
attribute1="value1"
392+
attribute2="value2"
393+
attribute3="value3">
394+
<child />
395+
<child />
396+
</robot>
397+
```
398+
***

package-lock.json

Lines changed: 19 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@
257257
"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.",
258258
"scope": "window"
259259
},
260+
"xml.format.numberOfIndentsForSplitAttributes": {
261+
"type": "number",
262+
"default": 2,
263+
"markdownDescription": "How many levels to indent the attributes by when `xml.format.splitAttributes` is `true`. See [here](command:xml.open.docs?%5B%7B%22page%22%3A%22Formatting%22%2C%22section%22%3A%22xmlformatnumberofindentsforsplitattributes%22%7D%5D) for more information"
264+
},
260265
"xml.preferences.quoteStyle": {
261266
"type": "string",
262267
"enum": [

0 commit comments

Comments
 (0)