Skip to content

Commit

Permalink
pull up new settings and readme updates
Browse files Browse the repository at this point in the history
pull up new settings and readme updates
  • Loading branch information
pmahend1 authored Jul 30, 2021
2 parents 1616dae + 3471268 commit b9810a5
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 366 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

## Preview

### 0.9.0 : 07-Jul-2021
- Added settings :
- `prettyxml.settings.allowSingleQuoteInAttributeValue`
- `prettyxml.settings.addSpaceBeforeSelfClosingTag`
- `prettyxml.settings.wrapCommentTextWithSpaces`

- Updated **Readme.md**.

### 0.8.1

- Fix for [#66:The edge module has not been pre-compiled for node.js version v14.16.0](https://github.com/pmahend1/PrettyXML/issues/66)

### 0.7.3

- Yarn security updates
Expand Down
36 changes: 24 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ Suggestions , improvement PRs are welcome.

![Deploy](https://img.shields.io/github/workflow/status/pmahend1/prettyxml/Deploy%20CI?color=brightgreen&label=Deploy%20CI&style=flat-square&logo=github) ![Installs](https://vsmarketplacebadge.apphb.com/installs/PrateekMahendrakar.PrettyXML.svg?style=flat-square&label=Installs&logo=data:img/png:images/logo.png) ![Downloads](https://vsmarketplacebadge.apphb.com/downloads/PrateekMahendrakar.PrettyXML.svg?style=flat-square&label=Downloads) ![Rating](https://vsmarketplacebadge.apphb.com/rating-star/PrateekMahendrakar.PrettyXML.svg?style=flat-square&label=Rating)

![Trending-Weekly](https://vsmarketplacebadge.apphb.com/trending-weekly/PrateekMahendrakar.PrettyXML.svg?labelColor=red&logo=tinder&logoColor=white&label=Trending%20Weekly) ![Trending-Monthly](https://vsmarketplacebadge.apphb.com/trending-monthly/PrateekMahendrakar.PrettyXML.svg?labelColor=red&logo=tinder&logoColor=white&label=Trending%20Monthly)
<!-- ![Trending-Weekly](https://vsmarketplacebadge.apphb.com/trending-weekly/PrateekMahendrakar.PrettyXML.svg?labelColor=red&logo=tinder&logoColor=white&label=Trending%20Weekly) ![Trending-Monthly](https://vsmarketplacebadge.apphb.com/trending-monthly/PrateekMahendrakar.PrettyXML.svg?labelColor=red&logo=tinder&logoColor=white&label=Trending%20Monthly) -->

[<img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" width="150" height="40" />](https://www.buymeacoffee.com/pmahend1)

---
![prettify gif](./images/Prettify.gif)

## Features

Expand All @@ -28,7 +29,7 @@ Suggestions , improvement PRs are welcome.
Right Click and Select Prettify XML or use [shortcut](#keyboard-shortcuts)

- First attribute on same line as start tag.
- All attributes indented in line with first attribute.
- All attributes indented aligning with first attribute.
- If no child for an element then close inline end tag.(Setting)
- No empty lines.

Expand All @@ -40,7 +41,14 @@ Suggestions , improvement PRs are welcome.

### Prettify XML

![prettify gif](./images/Prettify.gif)
- *before*

![Before](./images/before.png)

- **After**

![After](./images/after.png)


### PrettyXML: Minimize

Expand All @@ -55,26 +63,30 @@ Suggestions , improvement PRs are welcome.
| PrettyXML: Minimize | Mac | **Cmd+K \`** |
| PrettyXML: Minimize | Windows, Linux | **Control+K \`** |

## Formatted Document Example
> **Note**
>
> You can change these in **Preferences → Keyboard Shortcuts** if you want.
![Screenshot](./images/screenshot.png)

## Settings

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

| Setting Key | Default Value | Description |
|--------------------------------------|---------------|--------------------------------------------|
| prettyxml.settings.indentSpaceLength | 2 | 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 |
| 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 |

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

## Requirements

VS Code 1.47 or higher.
VS Code 1.48 or higher.

## Installation

Expand Down
Binary file modified images/Prettify.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/after.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 added images/before.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 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/Newtonsoft.Json.dll
Binary file not shown.
Binary file modified lib/XmlFormatter.VSCode.dll
Binary file not shown.
Binary file modified lib/XmlFormatter.dll
Binary file not shown.
48 changes: 31 additions & 17 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/master/README.md",
"description": "XML formatter extension for Visual Studio Code. Formats XML documents just like Visual Studio.",
"version": "0.8.1",
"version": "0.9.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down Expand Up @@ -34,7 +34,7 @@
"formatter"
],
"engines": {
"vscode": "^1.52.0"
"vscode": "^1.58.0"
},
"categories": [
"Formatters"
Expand Down Expand Up @@ -110,29 +110,42 @@
"properties": {
"prettyxml.settings.indentSpaceLength": {
"type": "number",
"description": "No. of spaces for indentation.",
"markdownDescription": "No. of spaces for indentation.",
"default": 2,
"maximum": 10,
"minimum": 1
"enum": [
2,
4,
8
],
"markdownDescription": "No. of spaces for indentation.\n Default is 4"
},
"prettyxml.settings.useSingleQuotes": {
"type": "boolean",
"description": "Use ' instead of \"",
"markdownDescription": "Use ' instead of \"",
"markdownDescription": "Use apostrophe `'` instead of quotes `\"` \n\n **Checked** : `Attribute='Value'` \n\n **Unchecked** : `Attribute=\"Value\"`",
"default": false
},
"prettyxml.settings.useSelfClosingTag": {
"type": "boolean",
"description": "If no child nodes then self closing tag />",
"markdownDescription": "If no child nodes then self closing tag />",
"markdownDescription": "If no child nodes then use self closing tag `/>` \n\n **Checked** : `<Foo></Foo>` → `<Foo/>` \n\n **Unchecked** : `<Foo></Foo>` → `<Foo></Foo>`",
"default": true
},
"prettyxml.settings.formatOnSave": {
"type": "boolean",
"description": "Enable format on save.",
"markdownDescription": "Enable format on save.",
"default": false
},
"prettyxml.settings.allowSingleQuoteInAttributeValue": {
"type": "boolean",
"markdownDescription": "Allow single quote in attribute values.\n\n **Checked** : `Attribute=\"Value'has'apostrphoes\"` \n\n **Unchecked** : `Attribute=\"Value&apos;has&apos;apostrphoes\"` \n\n Ignored if *Use Single Quotes* is *Checked*",
"default": true
},
"prettyxml.settings.addSpaceBeforeSelfClosingTag": {
"type": "boolean",
"markdownDescription": "Add space before self closing tag.\n\n **Checked** : `<Foo />` \n\n **Unchecked** : `<Foo/>`",
"default": true
},
"prettyxml.settings.wrapCommentTextWithSpaces": {
"type": "boolean",
"markdownDescription": "Wrap Comment text with spaces\n\n **Checked** : `<!-- Comment Text -->` \n\n **Unchecked** : `<!--Comment Text-->`",
"default": true
}
}
}
Expand All @@ -149,20 +162,21 @@
"devDependencies": {
"@types/glob": "^7.1.3",
"@types/mocha": "^8.0.0",
"@types/node": "^15.6.1",
"@types/vscode": "^1.52.0",
"@types/node": "^16.3.1",
"@types/vscode": "^1.58.0",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "4.25.0",
"@typescript-eslint/parser": "4.28.2",
"electron-rebuild": "^2.3.5",
"eslint": "^7.6.0",
"glob": "^7.1.6",
"mocha": "^8.1.3",
"mocha": "^9.0.2",
"typescript": "^4.1.3",
"vsce": "^1.81.1",
"vscode-test": "^1.4.0"
},
"dependencies": {
"electron-edge-js": "file:./lib/electron-edge-js",
"electron-edge-js-mac": "file:./lib/electron-edge-js-mac"
"electron-edge-js-mac": "file:./lib/electron-edge-js-mac",
"install": "^0.13.0"
}
}
15 changes: 10 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function activate(context: vscode.ExtensionContext)
break;
}

//prettyfy command definition
//prettify command definition
let prettifyXmlCommand = vscode.commands.registerTextEditorCommand("prettyxml.prettifyxml",
() =>
{
Expand Down Expand Up @@ -95,8 +95,11 @@ async function format()
let usesinglequotes = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('useSingleQuotes');
let useselfclosetag = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('useSelfClosingTag');
let formatOnSave = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('formatOnSave');
let allowSingleQuoteInAttributeValue = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('allowSingleQuoteInAttributeValue');
let addSpaceBeforeSelfClosingTag = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('addSpaceBeforeSelfClosingTag');
let wrapCommentTextWithSpaces = vscode.workspace.getConfiguration('prettyxml.settings').get<boolean>('wrapCommentTextWithSpaces');

var settings = new Settings(spacelength, usesinglequotes, useselfclosetag, formatOnSave);
var settings = new Settings(spacelength, usesinglequotes, useselfclosetag, formatOnSave, allowSingleQuoteInAttributeValue, addSpaceBeforeSelfClosingTag, wrapCommentTextWithSpaces);

var docText = vscode?.window.activeTextEditor?.document?.getText();
var ranger = getEditorRange();
Expand All @@ -115,11 +118,14 @@ async function format()
docText,
settings.IndentLength,
settings.UseSingleQuotes,
settings.UseSelfClosingTags
settings.UseSelfClosingTags,
settings.AllowSingleQuoteInAttributeValue,
settings.AddSpaceBeforeSelfClosingTag,
settings.WrapCommentTextWithSpaces
);

//convert to string
var inputstr = JSON.stringify(jsinput);

var editor = vscode.window.activeTextEditor;
//call C# method from DLL
await formatCSharp(inputstr, function (error: any, result: any)
Expand All @@ -131,7 +137,6 @@ async function format()
editBuilder.replace(ranger, result + "");
});
console.log("Document formatted!");

}
else if (error)
{
Expand Down
32 changes: 20 additions & 12 deletions src/jsinputdto.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
/* eslint-disable @typescript-eslint/naming-convention */

import { DefaultSettings } from "./settings";


interface IJSInputDto
{
XMLString: string;
IndentLength?: number;
UseSingleQuotes?: boolean;
UseSelfClosingTags?: boolean;
AllowSingleQuoteInAttributeValue?: boolean;
AddSpaceBeforeSelfClosingTag?: boolean;
WrapCommentTextWithSpaces?: boolean;
}


export class JSInputDTO
{
XMLString: string;
IndentLength: number;
UseSingleQuotes: boolean;
UseSelfClosingTags: boolean;
AllowSingleQuoteInAttributeValue: boolean;
AddSpaceBeforeSelfClosingTag: boolean;
WrapCommentTextWithSpaces: boolean;

constructor(XMLString: string,
IndentLength: number = DefaultSettings.IndentLength,
UseSingleQuotes: boolean = DefaultSettings.UseSingleQuotes,
UseSelfClosingTags: boolean = DefaultSettings.UseSelfClosingTags)
constructor(xmlString: string,
indentLength: number = DefaultSettings.IndentLength,
useSingleQuotes: boolean = DefaultSettings.UseSingleQuotes,
useSelfClosingTags: boolean = DefaultSettings.UseSelfClosingTags,
allowSingleQuoteInAttributeValue: boolean = DefaultSettings.AllowSingleQuoteInAttributeValue,
addSpaceBeforeSelfClosingTag: boolean = DefaultSettings.AddSpaceBeforeSelfClosingTag,
wrapCommentTextWithSpaces: boolean = DefaultSettings.WrapCommentTextWithSpaces)
{
this.XMLString = XMLString;
this.IndentLength = IndentLength;
this.UseSingleQuotes = UseSingleQuotes;
this.UseSelfClosingTags = UseSelfClosingTags;
this.XMLString = xmlString;
this.IndentLength = indentLength;
this.UseSingleQuotes = useSingleQuotes;
this.UseSelfClosingTags = useSelfClosingTags;
this.AllowSingleQuoteInAttributeValue = allowSingleQuoteInAttributeValue;
this.AddSpaceBeforeSelfClosingTag = addSpaceBeforeSelfClosingTag;
this.WrapCommentTextWithSpaces = wrapCommentTextWithSpaces;
}

}
32 changes: 24 additions & 8 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,46 @@ export interface ISettings
IndentLength: number;
UseSingleQuotes: boolean;
UseSelfClosingTags: boolean;
FormatOnSave : boolean;
FormatOnSave: boolean;
AllowSingleQuoteInAttributeValue: boolean;
AddSpaceBeforeSelfClosingTag: boolean;
WrapCommentTextWithSpaces: boolean;
}

export const DefaultSettings: ISettings = {
IndentLength: 2,
UseSingleQuotes: false,
UseSelfClosingTags: true,
FormatOnSave : false,
FormatOnSave: false,
AllowSingleQuoteInAttributeValue: true,
AddSpaceBeforeSelfClosingTag: true,
WrapCommentTextWithSpaces: true
};

export class Settings
{
IndentLength?: number;
UseSingleQuotes?: boolean;
UseSelfClosingTags?: boolean ;
FormatOnSave?:boolean;
UseSelfClosingTags?: boolean;
FormatOnSave?: boolean;
AllowSingleQuoteInAttributeValue?: boolean;
AddSpaceBeforeSelfClosingTag?: boolean;
WrapCommentTextWithSpaces?: boolean;

constructor(indentLengh?:number, useSingleQuotes?:boolean, useSelfClosingTags?:boolean, formatOnSave?:boolean)
constructor(indentLengh?: number,
useSingleQuotes?: boolean,
useSelfClosingTags?: boolean,
formatOnSave?: boolean,
allowSingleQuoteInAttributeValue?: boolean,
addSpaceBeforeSelfClosingTag?: boolean,
wrapCommentTextWithSpaces?: boolean)
{
this.IndentLength = indentLengh ?? DefaultSettings.IndentLength;
this.UseSingleQuotes = useSingleQuotes ?? DefaultSettings.UseSingleQuotes;
this.UseSelfClosingTags = useSelfClosingTags?? DefaultSettings.UseSelfClosingTags;
this.UseSelfClosingTags = useSelfClosingTags ?? DefaultSettings.UseSelfClosingTags;
this.FormatOnSave = formatOnSave ?? DefaultSettings.FormatOnSave;
this.AllowSingleQuoteInAttributeValue = allowSingleQuoteInAttributeValue;
this.AddSpaceBeforeSelfClosingTag = addSpaceBeforeSelfClosingTag ?? DefaultSettings.AddSpaceBeforeSelfClosingTag;
this.WrapCommentTextWithSpaces = wrapCommentTextWithSpaces ?? DefaultSettings.WrapCommentTextWithSpaces;
}
}


Loading

0 comments on commit b9810a5

Please sign in to comment.