Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setting to ignore all attributes on first line setting condtionally for specified element name patterns #171

Merged
merged 7 commits into from
Dec 26, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Stable

## 5.2.0: 26-Dec-2024

- Added feature [Allow the user to specify which elements have attributes on separate lines](https://github.com/pmahend1/PrettyXML/issues/162)
- Package updates to latest.

## 5.1.0: 29-Nov-2024

- Fixes [Formatting doesn't seem to work when using with .xaml files.](https://github.com/pmahend1/PrettyXML/issues/167)
Expand Down
76 changes: 57 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Pretty XML

<img src='./images/logo.png' width='200' height='200' />
<!-- markdownlint-disable-next-line MD033 -->
<img src='./images/logo.png' width='200' height='200' alt="logo" />

[What is it?](#what-is-it)

Expand Down Expand Up @@ -104,22 +105,23 @@ Minimizes XML.

These will be for **Prettify XML** command.

| Setting Key | Default Value | Description |
|-------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------|
| prettyxml.settings.indentSpaceLength | 4 | No. of spaces for indentation. |
| prettyxml.settings.useSingleQuotes | false | Use ' instead of \" |
| prettyxml.settings.useSelfClosingTag | true | If no child nodes then self closing tag /> |
| prettyxml.settings.formatOnSave | false | Enable format on save |
| prettyxml.settings.allowSingleQuoteInAttributeValue | true | Allows ' in attribute values instead of \&apos; |
| prettyxml.settings.addSpaceBeforeSelfClosingTag | true | Adds space before self closing tag |
| prettyxml.settings.wrapCommentTextWithSpaces | true | Wraps comment text with a single space |
| 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.addSpaceBeforeEndOfXmlDeclaration | false | Add space before end of XML declaration. |
| [prettyxml.settings.attributesInNewlineThreshold](#attributes-in-newline-threshold) | 1 | Attributes count threshold to position attributes in newlines. |
| prettyxml.settings.enableLogs | false | Enables logs |
| Setting Key | Default Value | Description |
|-------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------------------|
| prettyxml.settings.indentSpaceLength | 4 | No. of spaces for indentation. |
| prettyxml.settings.useSingleQuotes | false | Use ' instead of \" |
| prettyxml.settings.useSelfClosingTag | true | If no child nodes then self closing tag /> |
| prettyxml.settings.formatOnSave | false | Enable format on save |
| prettyxml.settings.allowSingleQuoteInAttributeValue | true | Allows ' in attribute values instead of \&apos; |
| prettyxml.settings.addSpaceBeforeSelfClosingTag | true | Adds space before self closing tag |
| prettyxml.settings.wrapCommentTextWithSpaces | true | Wraps comment text with a single space |
| 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.addSpaceBeforeEndOfXmlDeclaration | false | Add space before end of XML declaration. |
| [prettyxml.settings.attributesInNewlineThreshold](#attributes-in-newline-threshold) | 1 | Attributes count threshold to position attributes in newlines. |
| 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 |

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

Expand Down Expand Up @@ -155,6 +157,42 @@ Value = 2
Attribute3="Value3"/>
```

### Wild Carded Exceptions For Position All Attributes On First Line

List of element names to ignore Position All Attributes On First Line setting. Include element names or patterns here.

Example:

```json
"prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine": ["Content*"]
```

#### Input

```xml
<View>
<Content X="X"
Y="Y" Z="Z">
<Label text="{i18>LabelText}" />
<Input id="Input1"
value="{service>description}" />
</Content>
</View>
```

#### Ouput

```xml
<View>
<Content X="X"
Y="Y"
Z="Z">
<Label text="{i18>LabelText}" />
<Input id="Input1" value="{service>description}" />
</Content>
</View>
```

---

## Requirements
Expand Down Expand Up @@ -185,5 +223,5 @@ Issues can be reported at [issues section](https://github.com/pmahend1/PrettyXML
### For more information

- [Source Code](https://github.com/pmahend1/prettyxml)
- If you want to support this project,
[<img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" width="100" height="25" />](https://www.buymeacoffee.com/pmahend1)
- If you want to support this project, <!-- markdownlint-disable-next-line MD033 -->
[<img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" width="90" height="30" alt="buy-me-coffee"/>](https://www.buymeacoffee.com/pmahend1)
5 changes: 4 additions & 1 deletion lib/XmlFormatter.CommandLine.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
},
"XmlFormatter/1.0.0": {
"runtime": {
"XmlFormatter.dll": {}
"XmlFormatter.dll": {
"assemblyVersion": "1.0.0",
"fileVersion": "1.0.0.0"
}
}
}
}
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.
30 changes: 17 additions & 13 deletions 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": "5.1.0",
"version": "5.2.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down Expand Up @@ -165,6 +165,11 @@
"markdownDescription": "Position all attributes on same line as element. Setting this to *Checked* will ignore *Position First Attribute On Same Line*=*Unchecked*. *Default* is *Unchecked.* \n\n **Checked** : \n\n `<Element Attribute1=\"Value1\" Attribute2=\"Value2\"` \n\n **Unchecked** :\n\n`<Element Attribute1=\"Value1\"`\n\n&emsp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;`Attribute2=\"Value2\"` ",
"default": false
},
"prettyxml.settings.wildCardedExceptionsForPositionAllAttributesOnFirstLine": {
"type": "array",
"markdownDescription": "Exceptions for Position all attributes on same line as element. Wildcards accepted.",
"default": []
},
"prettyxml.settings.preserveWhiteSpacesInComment": {
"type": "boolean",
"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-->`",
Expand Down Expand Up @@ -212,25 +217,24 @@
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.10",
"@types/node": "^22.10.1",
"@types/vscode": "^1.95.0",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "8.16.0",
"esbuild": "^0.24.0",
"eslint": "^9.15.0",
"@types/node": "^22.10.2",
"@types/vscode": "^1.96.0",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "8.18.2",
"@vscode/test-electron": "^2.4.1",
"esbuild": "^0.24.2",
"eslint": "^9.17.0",
"glob": "^11.0.0",
"mocha": "^10.8.2",
"mocha": "^11.0.1",
"ts-loader": "^9.5.1",
"typescript": "^5.7.2",
"vscode-test": "^1.4.0",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4"
"webpack": "^5.97.1",
"webpack-cli": "^6.0.1"
},
"dependencies": {
"@types/compare-versions": "^3.3.3",
"child_process": "^1.0.2",
"compare-versions": "^6.1.1",
"fs": "^0.0.1-security",
"fs": "0.0.1-security",
"path": "^0.12.7"
}
}
Loading
Loading