|
| 1 | +## Formatting |
| 2 | + |
| 3 | +### xml.format.enabled |
| 4 | + |
| 5 | + Set to `false` to disable XML formatting. Defaults to `true`. |
| 6 | + |
| 7 | +*** |
| 8 | + |
| 9 | +### xml.format.enforceQuoteStyle |
| 10 | + |
| 11 | +Enforce `preferred` quote style (set by `xml.preferences.quoteStyle`) or `ignore` quote style when formatting. |
| 12 | + |
| 13 | +For instance, when set to `preferred` with `xml.preferences.quoteStyle` set to `single`, the following document: |
| 14 | + |
| 15 | + ```xml |
| 16 | + <?xml version="1.0" encoding="UTF-8"?> |
| 17 | + <root> |
| 18 | + <child attribute='value' otherAttribute="otherValue"></child> |
| 19 | + </root> |
| 20 | + ``` |
| 21 | + |
| 22 | +will be formatted to: |
| 23 | + |
| 24 | + ```xml |
| 25 | + <?xml version='1.0' encoding='UTF-8'?> |
| 26 | + <root> |
| 27 | + <child attribute='value' otherAttribute='otherValue'></child> |
| 28 | + </root> |
| 29 | + ``` |
| 30 | + |
| 31 | +No changes to quotes will occur during formatting if `xml.format.enforceQuoteStyle` is set to `ignore`. |
| 32 | + |
| 33 | +*** |
| 34 | + |
| 35 | +### xml.format.emptyElements |
| 36 | + |
| 37 | +Expand/collapse empty elements. Available values are `ignore`, `collapse` and `expand`. Defaults to `ignore`. |
| 38 | +An empty element is an element which is empty or which contains only white spaces. |
| 39 | + |
| 40 | +Set to `collapse` to collapse empty elements during formatting. |
| 41 | + |
| 42 | + ```xml |
| 43 | + <example attr="value" ></example> |
| 44 | + ``` |
| 45 | + becomes... |
| 46 | + ```xml |
| 47 | + <example attr="value" /> |
| 48 | + ``` |
| 49 | + |
| 50 | +Set to `expand` to expand empty elements during formatting. |
| 51 | + |
| 52 | + ```xml |
| 53 | + <example attr="value" /> |
| 54 | + ``` |
| 55 | + becomes... |
| 56 | + ```xml |
| 57 | + <example attr="value" ></example> |
| 58 | + ``` |
| 59 | +*** |
| 60 | + |
| 61 | +### xml.format.preserveAttributeLineBreaks |
| 62 | + |
| 63 | +Preserve line breaks that appear before and after attributes. This setting is overridden if [xml.format.splitAttributes](Formatting#xmlformatsplitattributes-) is set to `true`. Default is `false`. |
| 64 | + |
| 65 | +If set to `true`, formatting does not change the following document: |
| 66 | + |
| 67 | + ```xml |
| 68 | + <?xml version='1.0' encoding='UTF-8'?> |
| 69 | + <root> |
| 70 | + <child |
| 71 | + attr1='value1' |
| 72 | + attr2='value2' |
| 73 | + attr3='value3'></child> |
| 74 | + </root> |
| 75 | + ``` |
| 76 | + |
| 77 | +If set to `false`, the document above becomes: |
| 78 | + |
| 79 | + ```xml |
| 80 | + <?xml version='1.0' encoding='UTF-8'?> |
| 81 | + <root> |
| 82 | + <child attr1='value1' attr2='value2' attr3='value3'></child> |
| 83 | + </root> |
| 84 | + ``` |
| 85 | + |
| 86 | +*** |
| 87 | + |
| 88 | +### xml.format.preservedNewlines |
| 89 | + |
| 90 | +The number of blank lines to leave between tags during formatting. |
| 91 | + |
| 92 | +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. |
| 93 | + |
| 94 | + For example, this document: |
| 95 | + ```xml |
| 96 | + <?xml version="1.0" encoding="UTF-8"?> |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + <root> |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + <child></child> |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + </root> |
| 109 | + ``` |
| 110 | + |
| 111 | + Will be replaced with: |
| 112 | + ```xml |
| 113 | + <?xml version="1.0" encoding="UTF-8"?> |
| 114 | + |
| 115 | + |
| 116 | + <root> |
| 117 | + |
| 118 | + |
| 119 | + <child></child> |
| 120 | + |
| 121 | + |
| 122 | + </root> |
| 123 | + ``` |
| 124 | + |
| 125 | +If this value is set to 0, then all blank lines will be removed during formatting. |
| 126 | + |
| 127 | + For example, this document: |
| 128 | + ```xml |
| 129 | + <?xml version="1.0" encoding="UTF-8"?> |
| 130 | + |
| 131 | + <root> |
| 132 | + |
| 133 | + <child></child> |
| 134 | + |
| 135 | + </root> |
| 136 | + ``` |
| 137 | + |
| 138 | + Will be replaced with: |
| 139 | + ```xml |
| 140 | + <?xml version="1.0" encoding="UTF-8"?> |
| 141 | + <root> |
| 142 | + <child></child> |
| 143 | + </root> |
| 144 | + ``` |
| 145 | + |
| 146 | +*** |
| 147 | + |
| 148 | +### xml.format.splitAttributes |
| 149 | + |
| 150 | + Set to `true` to split node attributes onto multiple lines during formatting. Defaults to `false`. |
| 151 | + Overrides the behaviour of [xml.format.preserveAttributeLineBreaks](Formatting#xmlformatpreserveattributelinebreaks) |
| 152 | + |
| 153 | + ```xml |
| 154 | + <project a="1" b="2" c="3"></project> |
| 155 | + ``` |
| 156 | + becomes... |
| 157 | + ```xml |
| 158 | + <project |
| 159 | + a="1" |
| 160 | + b="2" |
| 161 | + c="3"></project> |
| 162 | + ``` |
| 163 | + |
| 164 | +*** |
| 165 | + |
| 166 | +### xml.format.joinCDATALines |
| 167 | + |
| 168 | + Set to `true` to join lines in CDATA content during formatting. Defaults to `false`. |
| 169 | + ```xml |
| 170 | + <![CDATA[This |
| 171 | + is |
| 172 | + a |
| 173 | + test |
| 174 | + ]]> |
| 175 | + ``` |
| 176 | + becomes... |
| 177 | + ```xml |
| 178 | + <![CDATA[This is a test ]]> |
| 179 | + ``` |
| 180 | +*** |
| 181 | + |
| 182 | +### xml.format.preserveEmptyContent |
| 183 | + |
| 184 | + Set to `true` to preserve empty whitespace content. |
| 185 | + ```xml |
| 186 | + <project> </project> |
| 187 | + |
| 188 | + <a> </a> |
| 189 | + ``` |
| 190 | + becomes... |
| 191 | + ```xml |
| 192 | + <project> </project> |
| 193 | + <a> </a> |
| 194 | + ``` |
| 195 | +*** |
| 196 | +### xml.format.joinCommentLines |
| 197 | + |
| 198 | + Set to `true` to join lines in comments during formatting. Defaults to `false`. |
| 199 | + ```xml |
| 200 | + <!-- This |
| 201 | + is |
| 202 | + my |
| 203 | +
|
| 204 | + comment --> |
| 205 | + ``` |
| 206 | + becomes... |
| 207 | + ```xml |
| 208 | + <!-- This is my comment --> |
| 209 | + ``` |
| 210 | + |
| 211 | +*** |
| 212 | + |
| 213 | +### xml.format.joinContentLines |
| 214 | + |
| 215 | +Normalize the whitespace of content inside an element. Newlines and excess whitespace are removed. Default is `false`. |
| 216 | + |
| 217 | +For example, the following document doesn't change if it is set to `false`: |
| 218 | + |
| 219 | + ```xml |
| 220 | + <?xml version='1.0' encoding='UTF-8'?> |
| 221 | + <root> |
| 222 | + Interesting text content |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + values and 1234 numbers |
| 227 | + |
| 228 | + </root> |
| 229 | + ``` |
| 230 | + |
| 231 | +If it is set to `true`, the above document becomes: |
| 232 | + |
| 233 | + ```xml |
| 234 | + <?xml version='1.0' encoding='UTF-8'?> |
| 235 | + <root>Interesting text content values and 1234 numbers</root> |
| 236 | + ``` |
| 237 | + |
| 238 | +*** |
| 239 | + |
| 240 | +### xml.format.spaceBeforeEmptyCloseTag |
| 241 | + |
| 242 | + Set to `true` to insert a space before the end of self closing tags. Defaults to `true` |
| 243 | + ```xml |
| 244 | + <tag/> |
| 245 | + ``` |
| 246 | + becomes... |
| 247 | + ```xml |
| 248 | + <tag /> |
| 249 | + ``` |
| 250 | + |
| 251 | +*** |
| 252 | + |
| 253 | +### files.insertFinalNewline |
| 254 | + |
| 255 | + Set to `true` to insert a final newline at the end of the document. Defaults to `false` |
| 256 | + ```xml |
| 257 | + <a><a/> |
| 258 | + ``` |
| 259 | + becomes... |
| 260 | + ```xml |
| 261 | + <a><a/> |
| 262 | + |
| 263 | + |
| 264 | + ``` |
| 265 | + |
| 266 | +*** |
| 267 | + |
| 268 | +### files.trimFinalNewlines |
| 269 | + |
| 270 | + Set to `true` to trim final newlines at the end of the document. Defaults to `false` |
| 271 | + ```xml |
| 272 | + <a><a/> |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + ``` |
| 278 | + becomes... |
| 279 | + ```xml |
| 280 | + <a><a/> |
| 281 | + ``` |
| 282 | + |
| 283 | +*** |
0 commit comments