Skip to content

Commit

Permalink
Attributes in newline threshold setting added (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmahend1 authored Feb 25, 2024
1 parent b3b0247 commit fc55ec8
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 3 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.4.0: 25-Feb-2024

- **Attributes In Newline Threshold** setting added.

## 4.3.0: 23-Feb-2024

- Fixed some CDATA and text formatting.
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.
18 changes: 17 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.3.0",
"version": "4.4.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down Expand Up @@ -173,6 +173,22 @@
"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.attributesInNewlineThreshold": {
"type": "number",
"default": 1,
"enum": [
1,
2,
3,
4,
5,
6,
7,
8,
9
],
"markdownDescription": "Attributes count threshold to position attributes in newlines. Default is *1*. This setting only works when **Position first attribute on same line** is enabled.\n\nFor example if threshold=2, all attributes will be on same line if an element has only 2 attributes,\n\notherwise each attribute will be placed on newline."
},
"prettyxml.settings.enableLogs": {
"type": "boolean",
"markdownDescription": "Enable console local logs.",
Expand Down
6 changes: 4 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export class Formatter {
let positionAllAttributesOnFirstLine = prettyXmlConfig.get<boolean>('positionAllAttributesOnFirstLine');
let preserveWhiteSpacesInComment = prettyXmlConfig.get<boolean>('preserveWhiteSpacesInComment');
let addSpaceBeforeEndOfXmlDeclaration = prettyXmlConfig.get<boolean>('addSpaceBeforeEndOfXmlDeclaration');
let attributesInNewlineThreshold = prettyXmlConfig.get<number>("attributesInNewlineThreshold");
let enableLogs = prettyXmlConfig.get<boolean>('enableLogs');
Logger.instance.updateConfiguration(enableLogs);

this.settings = new Settings(spacelength,
usesinglequotes,
useselfclosetag,
Expand All @@ -72,10 +73,11 @@ export class Formatter {
positionAllAttributesOnFirstLine,
preserveWhiteSpacesInComment,
addSpaceBeforeEndOfXmlDeclaration,
attributesInNewlineThreshold,
enableLogs);

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

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

Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ISettings {
positionAllAttributesOnFirstLine: boolean;
preserveWhiteSpacesInComment: boolean;
addSpaceBeforeEndOfXmlDeclaration: boolean;
attributesInNewlineThreshold: number;
enableLogs: boolean;
}

Expand All @@ -27,6 +28,7 @@ export const defaultSettings: ISettings = {
positionAllAttributesOnFirstLine: false,
preserveWhiteSpacesInComment: false,
addSpaceBeforeEndOfXmlDeclaration: false,
attributesInNewlineThreshold: 1,
enableLogs: false
};

Expand All @@ -43,6 +45,7 @@ export class Settings {
positionAllAttributesOnFirstLine?: boolean;
preserveWhiteSpacesInComment?: boolean;
addSpaceBeforeEndOfXmlDeclaration: boolean;
attributesInNewlineThreshold: number;
enableLogs?: boolean;

constructor(indentLengh?: number,
Expand All @@ -57,6 +60,7 @@ export class Settings {
positionAllAttributesOnFirstLine?: boolean,
preserveWhiteSpacesInComment?: boolean,
addSpaceBeforeEndOfXmlDeclaration?: boolean,
attributesInNewlineThreshold?: number,
enableLogs?: boolean) {
this.indentLength = indentLengh ?? defaultSettings.indentLength;
this.useSingleQuotes = useSingleQuotes ?? defaultSettings.useSingleQuotes;
Expand All @@ -70,6 +74,7 @@ export class Settings {
this.positionAllAttributesOnFirstLine = positionAllAttributesOnFirstLine ?? defaultSettings.positionAllAttributesOnFirstLine;
this.preserveWhiteSpacesInComment = preserveWhiteSpacesInComment ?? defaultSettings.preserveWhiteSpacesInComment;
this.addSpaceBeforeEndOfXmlDeclaration = addSpaceBeforeEndOfXmlDeclaration ?? defaultSettings.addSpaceBeforeEndOfXmlDeclaration;
this.attributesInNewlineThreshold = attributesInNewlineThreshold ?? defaultSettings.attributesInNewlineThreshold;
this.enableLogs = enableLogs ?? defaultSettings.enableLogs;
}
}

0 comments on commit fc55ec8

Please sign in to comment.