Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Stable

## 6.6.0: 25-Dec-2025

- Added [Preserve New Lines](README.md#preserve-new-lines) setting.

## 6.5.0: 25-Dec-2025

- Changed dotnet dependency from Dotnet 8 to Dotnet 10.
Expand Down
78 changes: 70 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ These will be for **Prettify XML** command.
| prettyxml.settings.enableLogs | false | Enables logs |
| [prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine](#wild-carded-exceptions-for-position-all-attributes-on-first-line) | Array\<string\> | Wild card exceptions for elements to ignore positionAllAttributesOnFirstLine |
| [prettyxml.settings.addEmptyLineBetweenElements](#add-empty-line-between-elements) | false | Add empty line between elements if the child count is greater than 2 |
| [prettyxml.settings.preserveNewLines](#preserve-new-lines) | false | Preserve existing new lines between elements. |

![Settings Image.](./images/settings.png)

Expand All @@ -143,25 +144,25 @@ Example:

Value = 2

#### Input#1
#### Input 1

```xml
<Element Attribute1="Value1" Attribute2="Value2" />
```

#### Output#1
#### Output 1

```xml
<Element Attribute1="Value1" Attribute2="Value2" />
```

#### Input#2
#### Input 2

```xml
<Element Attribute1="Value1" Attribute2="Value2" Attribute3="Value3" />
```

#### Output#2
#### Output 2

```xml
<Element Attribute1="Value1"
Expand All @@ -179,7 +180,7 @@ Example:
"prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine": ["Content*"]
```

#### Input
#### Input 3

```xml
<View>
Expand All @@ -192,7 +193,7 @@ Example:
</View>
```

#### Ouput
#### Ouput 3

```xml
<View>
Expand All @@ -212,7 +213,7 @@ If enabled, and child elements count is greater than 2 then adds empty line betw
> [!NOTE]
> Please note it wont add empty element before first element and after last element.

#### Input 1
#### Input 4

```xml
<Root>
Expand All @@ -222,7 +223,7 @@ If enabled, and child elements count is greater than 2 then adds empty line betw
</Root>
```

#### Output 1
#### Output 4

```xml
<Root>
Expand All @@ -239,6 +240,67 @@ If enabled, and child elements count is greater than 2 then adds empty line betw
Adds XML declaration `<?xml version="1.0" encoding="utf-8"?>` if missing.
Default is `true`.

### Preserve New Lines

Preserves existing new lines between elements.

Example: Value = **false**

#### Input 5

```xml
<Root>
<Element1>Text1</Element1>


<Element2>Text2</Element2>

<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>
```

#### Output 5

```xml
<Root>
<Element1>Text1</Element1>
<Element2>Text2</Element2>
<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>
```

Example: Value = **true**

#### Input 6

```xml
<Root>
<Element1>Text1</Element1>


<Element2>Text2</Element2>

<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>
```

#### Output 6

```xml
<Root>
<Element1>Text1</Element1>


<Element2>Text2</Element2>

<Element3>Text3</Element3>
<Element3>Text4</Element3>
</Root>
```

---

## Requirements
Expand Down
14 changes: 7 additions & 7 deletions lib/XmlFormatter.CommandLine.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v10.0": {
"XmlFormatter.CommandLine/2.0.0": {
"XmlFormatter.CommandLine/2.1.0": {
"dependencies": {
"XmlFormatter": "2.0.0"
"XmlFormatter": "2.1.0"
},
"runtime": {
"XmlFormatter.CommandLine.dll": {}
}
},
"XmlFormatter/2.0.0": {
"XmlFormatter/2.1.0": {
"runtime": {
"XmlFormatter.dll": {
"assemblyVersion": "2.0.0.0",
"fileVersion": "2.0.0.0"
"assemblyVersion": "2.1.0.0",
"fileVersion": "2.1.0.0"
}
}
}
}
},
"libraries": {
"XmlFormatter.CommandLine/2.0.0": {
"XmlFormatter.CommandLine/2.1.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"XmlFormatter/2.0.0": {
"XmlFormatter/2.1.0": {
"type": "project",
"serviceable": false,
"sha512": ""
Expand Down
Binary file modified lib/XmlFormatter.CommandLine.dll
Binary file not shown.
Binary file modified lib/XmlFormatter.CommandLine.exe
Binary file not shown.
Binary file modified lib/XmlFormatter.CommandLine.pdb
Binary file not shown.
Binary file modified lib/XmlFormatter.dll
Binary file not shown.
Binary file modified lib/XmlFormatter.pdb
Binary file not shown.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"readme": "https://github.com/pmahend1/PrettyXML/blob/main/README.md",
"description": "XML formatter extension for Visual Studio Code. Formats XML documents just like Visual Studio.",
"version": "6.5.0",
"version": "6.6.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down Expand Up @@ -209,6 +209,11 @@
"markdownDescription": "Add empty line between elements if element count is greater than 2. Default is *Unchecked*",
"default": false
},
"prettyxml.settings.preserveNewLines": {
"type": "boolean",
"markdownDescription": "Preserve existing new lines between elements. Default is *Unchecked*",
"default": false
},
"prettyxml.settings.enableLogs": {
"type": "boolean",
"markdownDescription": "Enable console local logs.",
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Constants = {
attributesInNewlineThreshold: "attributesInNewlineThreshold",
wildCardedExceptionsForPositionAllAttributesOnFirstLine: "wildCardedExceptionsForPositionAllAttributesOnFirstLine",
addEmptyLineBetweenElements: "addEmptyLineBetweenElements",
preserveNewLines: "preserveNewLines",
enableLogs: "enableLogs",
},

Expand Down
2 changes: 2 additions & 0 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Formatter {
let attributesInNewlineThreshold = prettyXmlConfig.get<number>(Constants.Settings.attributesInNewlineThreshold);
let wildCardedExceptionsForPositionAllAttributesOnFirstLine = prettyXmlConfig.get<Array<string>>(Constants.Settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine);
let addEmptyLineBetweenElements = prettyXmlConfig.get<boolean>(Constants.Settings.addEmptyLineBetweenElements);
let preserveNewLines = prettyXmlConfig.get<boolean>(Constants.Settings.preserveNewLines);
let enableLogs = prettyXmlConfig.get<boolean>(Constants.Settings.enableLogs);
Logger.instance.setIsEnabled(enableLogs);

Expand All @@ -82,6 +83,7 @@ export class Formatter {
attributesInNewlineThreshold: attributesInNewlineThreshold,
wildCardedExceptionsForPositionAllAttributesOnFirstLine: wildCardedExceptionsForPositionAllAttributesOnFirstLine,
addEmptyLineBetweenElements: addEmptyLineBetweenElements,
preserveNewLines: preserveNewLines,
enableLogs: enableLogs,
};

Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ISettings {
attributesInNewlineThreshold: number;
wildCardedExceptionsForPositionAllAttributesOnFirstLine?: [string];
addEmptyLineBetweenElements: boolean;
preserveNewLines: boolean;
enableLogs: boolean;
}

Expand All @@ -35,6 +36,7 @@ export const defaultSettings: ISettings = {
attributesInNewlineThreshold: 1,
wildCardedExceptionsForPositionAllAttributesOnFirstLine: undefined,
addEmptyLineBetweenElements: false,
preserveNewLines: false,
enableLogs: false
};

Expand All @@ -55,6 +57,7 @@ export class Settings {
attributesInNewlineThreshold?: number;
wildCardedExceptionsForPositionAllAttributesOnFirstLine?: string[];
addEmptyLineBetweenElements?: boolean;
preserveNewLines?: boolean;
enableLogs?: boolean;

constructor({
Expand All @@ -74,6 +77,7 @@ export class Settings {
attributesInNewlineThreshold,
wildCardedExceptionsForPositionAllAttributesOnFirstLine,
addEmptyLineBetweenElements,
preserveNewLines,
enableLogs
}: Partial<ISettings> = {}) {
this.indentLength = indentLength ?? defaultSettings.indentLength;
Expand All @@ -92,6 +96,7 @@ export class Settings {
this.attributesInNewlineThreshold = attributesInNewlineThreshold ?? defaultSettings.attributesInNewlineThreshold;
this.wildCardedExceptionsForPositionAllAttributesOnFirstLine = wildCardedExceptionsForPositionAllAttributesOnFirstLine;
this.addEmptyLineBetweenElements = addEmptyLineBetweenElements ?? defaultSettings.addEmptyLineBetweenElements;
this.preserveNewLines = preserveNewLines ?? defaultSettings.preserveNewLines;
this.enableLogs = enableLogs ?? defaultSettings.enableLogs;
}
}
Loading