Skip to content

Commit 0a17f59

Browse files
Merge pull request #186 from DotJoshJohnson/release-2.3.0
Release v2.3.0
2 parents 516cf1f + a29b2fc commit 0a17f59

10 files changed

+75
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
out
22
node_modules
33
.vscode-test/
4-
.vsix
4+
/*.vsix

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "xml",
33
"displayName": "XML Tools",
44
"description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
5-
"version": "2.2.0",
5+
"version": "2.3.0",
66
"preview": false,
77
"publisher": "DotJoshJohnson",
88
"author": {

src/formatting/formatters/v2-xml-formatter.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class V2XmlFormatter implements XmlFormatter {
3232
let indentLevel = 0;
3333
let location = Location.Text;
3434
let lastNonTextLocation = Location.Text; // hah
35+
let attributeQuote = "";
3536

3637
// NOTE: all "exiting" checks should appear after their associated "entering" checks
3738
for (let i = 0; i < xml.length; i++) {
@@ -126,13 +127,17 @@ export class V2XmlFormatter implements XmlFormatter {
126127
output += cc;
127128
lastNonTextLocation = location;
128129
location = Location.AttributeValue;
130+
131+
attributeQuote = cc;
129132
}
130133

131134
// exiting StartTag.Attribute.AttributeValue, entering StartTag
132-
else if (location === Location.AttributeValue && (cc === "\"" || cc === "'")) {
135+
else if (location === Location.AttributeValue && cc === attributeQuote) {
133136
output += cc;
134137
lastNonTextLocation = location;
135138
location = Location.StartTag;
139+
140+
attributeQuote = undefined;
136141
}
137142

138143
// approaching the end of a self-closing tag where there was no whitespace (issue #149)
@@ -169,7 +174,7 @@ export class V2XmlFormatter implements XmlFormatter {
169174
indentLevel--;
170175

171176
// if the end tag immediately follows a line break, just add an indentation
172-
// if the end tag immediately follows another end tag, add a line break and indent
177+
// if the end tag immediately follows another end tag or a self-closing tag (issue #185), add a line break and indent
173178
// otherwise, this should be treated as a same-line end tag(ex. <element>text</element>)
174179
if (pc === "\n") {
175180
output += `${this._getIndent(options, indentLevel)}<`;
@@ -179,6 +184,10 @@ export class V2XmlFormatter implements XmlFormatter {
179184
output += `${options.newLine}${this._getIndent(options, indentLevel)}<`;
180185
}
181186

187+
else if (pc === ">" && ppc === "/") {
188+
output += `${this._getIndent(options, indentLevel)}<`;
189+
}
190+
182191
else {
183192
output += "<";
184193
}

src/test/extension.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ describe("V2XmlFormatter", () => {
6868
options.enforcePrettySelfClosingTagOnFormat = false;
6969
});
7070

71+
it("should properly format closing tag after self-closing tag", () => {
72+
testFormatter(xmlFormatter, options, "issue-185");
73+
});
74+
75+
it("should support single quotes within double-quoptes attributes and vice-versa", () => {
76+
testFormatter(xmlFormatter, options, "issue-187");
77+
});
78+
79+
it("should not ruin attributes with unusual characters", () => {
80+
testFormatter(xmlFormatter, options, "issue-189");
81+
});
82+
7183
});
7284

7385
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<test>
2+
<example>
3+
<one/>
4+
</example>
5+
</test>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<test><example><one/></example></test>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
<PropertyGroup Condition=" '$(Configuration)'=='Release' ">
7+
<DebugSymbols>false</DebugSymbols>
8+
<DebugType>None</DebugType>
9+
<Optimize>true</Optimize>
10+
</PropertyGroup>
11+
<ItemGroup Condition=" '$(Configuration)'=='Release' ">
12+
<Content Remove="appsettings.Development.json" />
13+
</ItemGroup>
14+
<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
15+
<Content Remove="appsettings.Production.json" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
<LangVersion>latest</LangVersion>
5+
</PropertyGroup>
6+
<PropertyGroup Condition=" '$(Configuration)'=='Release' ">
7+
<DebugSymbols>false</DebugSymbols>
8+
<DebugType>None</DebugType>
9+
<Optimize>true</Optimize>
10+
</PropertyGroup>
11+
<ItemGroup Condition=" '$(Configuration)'=='Release' ">
12+
<Content Remove="appsettings.Development.json" />
13+
</ItemGroup>
14+
<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
15+
<Content Remove="appsettings.Production.json" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE xml>
2+
<core:FragmentDefinition xmlns="sap.m"
3+
xmlns:core="sap.ui.core">
4+
<Text text="{parts: ['i18n>dialog.countdown.text','view>/Countdown'],formatter: 'jQuery.sap.formatMessage'}" />
5+
</core:FragmentDefinition>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE xml>
2+
<core:FragmentDefinition xmlns="sap.m"
3+
xmlns:core="sap.ui.core">
4+
<Text text="{parts: ['i18n>dialog.countdown.text','view>/Countdown'],formatter: 'jQuery.sap.formatMessage'}" />
5+
</core:FragmentDefinition>

0 commit comments

Comments
 (0)