Skip to content

Commit

Permalink
Added space in xml declaration end setting (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmahend1 authored Feb 5, 2024
1 parent 5f45dec commit c5265c4
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 5 deletions.
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

### 4.2.0: 04-Feb-2024

- Added setting `addSpaceBeforeEndOfXmlDeclaration`

### 4.1.3: 03-Feb-2024

- Fix for [#141: Some comments are lost after format](https://github.com/pmahend1/PrettyXML/issues/141).
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ These will be for **Prettify XML** command.
| prettyxml.settings.allowWhiteSpaceUnicodesInAttributeValues | true | Allows white space unicodes in attribute values |
| prettyxml.settings.positionFirstAttributeOnSameLine | true | Position first attribute on same line. |
| prettyxml.settings.positionAllAttributesOnFirstLine | false | Position all attributes on first line |
| prettyxml.settings.preserveWhiteSpacesInComment | false | Preserves whitespaces in a comment |
| prettyxml.settings.preserveWhiteSpacesInComment | false | Preserves whitespaces in a comment |
| prettyxml.settings.addSpaceBeforeEndOfXmlDeclaration | false | Add space before end of XML declaration |
| prettyxml.settings.enableLogs | false | Enables logs |

![Settings Image.](./images/settings.png)
Expand Down
Binary file modified images/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -6,7 +6,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": "4.1.3",
"version": "4.2.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down Expand Up @@ -168,6 +168,11 @@
"markdownDescription": "Preserves whitespaces in comment. Setting this *Checked* ignores *Wrap Comment Text With Spaces* setting. Default is *Unchecked* \n\n **Checked** : \n\n `<!--`&ensp;&ensp;&ensp;&ensp;`Comment`&ensp;&ensp;&ensp;&ensp;`-->` \n\n **Unchecked** : \n\n `<!--Comment-->`",
"default": false
},
"prettyxml.settings.addSpaceBeforeEndOfXmlDeclaration": {
"type": "boolean",
"markdownDescription": "Adds space before end of XML declaration. Default is *Unchecked* \n\n **Checked** : \n\n `<?xml version=\"1.0\" encoding=\"utf-8\" ?>` \n\n **Unchecked** : \n\n `<?xml version=\"1.0\" encoding=\"utf-8\"?>`",
"default": false
},
"prettyxml.settings.enableLogs": {
"type": "boolean",
"markdownDescription": "Enable console local logs.",
Expand Down
8 changes: 6 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export class Formatter {
let positionFirstAttributeOnSameLine = prettyXmlConfig.get<boolean>('positionFirstAttributeOnSameLine');
let positionAllAttributesOnFirstLine = prettyXmlConfig.get<boolean>('positionAllAttributesOnFirstLine');
let preserveWhiteSpacesInComment = prettyXmlConfig.get<boolean>('preserveWhiteSpacesInComment');
let addSpaceBeforeEndOfXmlDeclaration = prettyXmlConfig.get<boolean>('addSpaceBeforeEndOfXmlDeclaration');
let enableLogs = prettyXmlConfig.get<boolean>('enableLogs');

Logger.instance.updateConfiguration(enableLogs);

this.settings = new Settings(spacelength,
usesinglequotes,
useselfclosetag,
Expand All @@ -69,9 +71,11 @@ export class Formatter {
positionFirstAttributeOnSameLine,
positionAllAttributesOnFirstLine,
preserveWhiteSpacesInComment,
addSpaceBeforeEndOfXmlDeclaration,
enableLogs);

Logger.instance.updateConfiguration(enableLogs);
Logger.instance.info(`Settings : ${JSON.stringify(this.settings)}`);

Logger.instance.info("loadSettings end");
}

Expand Down
7 changes: 6 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ISettings {
positionFirstAttributeOnSameLine: boolean;
positionAllAttributesOnFirstLine: boolean;
preserveWhiteSpacesInComment: boolean;
addSpaceBeforeEndOfXmlDeclaration: boolean;
enableLogs: boolean;
}

Expand All @@ -25,6 +26,7 @@ export const defaultSettings: ISettings = {
positionFirstAttributeOnSameLine: true,
positionAllAttributesOnFirstLine: false,
preserveWhiteSpacesInComment: false,
addSpaceBeforeEndOfXmlDeclaration: false,
enableLogs: false
};

Expand All @@ -40,9 +42,10 @@ export class Settings {
positionFirstAttributeOnSameLine?: boolean;
positionAllAttributesOnFirstLine?: boolean;
preserveWhiteSpacesInComment?: boolean;
addSpaceBeforeEndOfXmlDeclaration: boolean;
enableLogs?: boolean;

constructor(indentLengh?: number,
constructor(indentLengh?: number,
useSingleQuotes?: boolean,
useSelfClosingTags?: boolean,
formatOnSave?: boolean,
Expand All @@ -53,6 +56,7 @@ export class Settings {
positionFirstAttributeOnSameLine?: boolean,
positionAllAttributesOnFirstLine?: boolean,
preserveWhiteSpacesInComment?: boolean,
addSpaceBeforeEndOfXmlDeclaration?: boolean,
enableLogs?: boolean) {
this.indentLength = indentLengh ?? defaultSettings.indentLength;
this.useSingleQuotes = useSingleQuotes ?? defaultSettings.useSingleQuotes;
Expand All @@ -65,6 +69,7 @@ export class Settings {
this.positionFirstAttributeOnSameLine = positionFirstAttributeOnSameLine ?? defaultSettings.positionFirstAttributeOnSameLine;
this.positionAllAttributesOnFirstLine = positionAllAttributesOnFirstLine ?? defaultSettings.positionAllAttributesOnFirstLine;
this.preserveWhiteSpacesInComment = preserveWhiteSpacesInComment ?? defaultSettings.preserveWhiteSpacesInComment;
this.addSpaceBeforeEndOfXmlDeclaration = addSpaceBeforeEndOfXmlDeclaration ?? defaultSettings.addSpaceBeforeEndOfXmlDeclaration;
this.enableLogs = enableLogs ?? defaultSettings.enableLogs;
}
}

0 comments on commit c5265c4

Please sign in to comment.