diff --git a/.gitignore b/.gitignore
index 8c8220a..a337458 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
out
node_modules
.vscode-test/
-.vsix
+/*.vsix
diff --git a/package.json b/package.json
index c4ec2b2..009eb8c 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "xml",
"displayName": "XML Tools",
"description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
- "version": "2.2.0",
+ "version": "2.3.0",
"preview": false,
"publisher": "DotJoshJohnson",
"author": {
diff --git a/src/formatting/formatters/v2-xml-formatter.ts b/src/formatting/formatters/v2-xml-formatter.ts
index c67b0c9..0d8af2a 100644
--- a/src/formatting/formatters/v2-xml-formatter.ts
+++ b/src/formatting/formatters/v2-xml-formatter.ts
@@ -32,6 +32,7 @@ export class V2XmlFormatter implements XmlFormatter {
let indentLevel = 0;
let location = Location.Text;
let lastNonTextLocation = Location.Text; // hah
+ let attributeQuote = "";
// NOTE: all "exiting" checks should appear after their associated "entering" checks
for (let i = 0; i < xml.length; i++) {
@@ -126,13 +127,17 @@ export class V2XmlFormatter implements XmlFormatter {
output += cc;
lastNonTextLocation = location;
location = Location.AttributeValue;
+
+ attributeQuote = cc;
}
// exiting StartTag.Attribute.AttributeValue, entering StartTag
- else if (location === Location.AttributeValue && (cc === "\"" || cc === "'")) {
+ else if (location === Location.AttributeValue && cc === attributeQuote) {
output += cc;
lastNonTextLocation = location;
location = Location.StartTag;
+
+ attributeQuote = undefined;
}
// approaching the end of a self-closing tag where there was no whitespace (issue #149)
@@ -169,7 +174,7 @@ export class V2XmlFormatter implements XmlFormatter {
indentLevel--;
// if the end tag immediately follows a line break, just add an indentation
- // if the end tag immediately follows another end tag, add a line break and indent
+ // if the end tag immediately follows another end tag or a self-closing tag (issue #185), add a line break and indent
// otherwise, this should be treated as a same-line end tag(ex. text)
if (pc === "\n") {
output += `${this._getIndent(options, indentLevel)}<`;
@@ -179,6 +184,10 @@ export class V2XmlFormatter implements XmlFormatter {
output += `${options.newLine}${this._getIndent(options, indentLevel)}<`;
}
+ else if (pc === ">" && ppc === "/") {
+ output += `${this._getIndent(options, indentLevel)}<`;
+ }
+
else {
output += "<";
}
diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts
index 50adb2b..45666e7 100644
--- a/src/test/extension.test.ts
+++ b/src/test/extension.test.ts
@@ -68,6 +68,18 @@ describe("V2XmlFormatter", () => {
options.enforcePrettySelfClosingTagOnFormat = false;
});
+ it("should properly format closing tag after self-closing tag", () => {
+ testFormatter(xmlFormatter, options, "issue-185");
+ });
+
+ it("should support single quotes within double-quoptes attributes and vice-versa", () => {
+ testFormatter(xmlFormatter, options, "issue-187");
+ });
+
+ it("should not ruin attributes with unusual characters", () => {
+ testFormatter(xmlFormatter, options, "issue-189");
+ });
+
});
});
diff --git a/src/test/test-data/issue-185.formatted.xml b/src/test/test-data/issue-185.formatted.xml
new file mode 100644
index 0000000..c91115a
--- /dev/null
+++ b/src/test/test-data/issue-185.formatted.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/test-data/issue-185.unformatted.xml b/src/test/test-data/issue-185.unformatted.xml
new file mode 100644
index 0000000..92db740
--- /dev/null
+++ b/src/test/test-data/issue-185.unformatted.xml
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/test/test-data/issue-187.formatted.xml b/src/test/test-data/issue-187.formatted.xml
new file mode 100644
index 0000000..2ad9048
--- /dev/null
+++ b/src/test/test-data/issue-187.formatted.xml
@@ -0,0 +1,17 @@
+
+
+ Debug
+ latest
+
+
+ false
+ None
+ true
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/test-data/issue-187.unformatted.xml b/src/test/test-data/issue-187.unformatted.xml
new file mode 100644
index 0000000..2ad9048
--- /dev/null
+++ b/src/test/test-data/issue-187.unformatted.xml
@@ -0,0 +1,17 @@
+
+
+ Debug
+ latest
+
+
+ false
+ None
+ true
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/test-data/issue-189.formatted.xml b/src/test/test-data/issue-189.formatted.xml
new file mode 100644
index 0000000..b3a3d19
--- /dev/null
+++ b/src/test/test-data/issue-189.formatted.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/test/test-data/issue-189.unformatted.xml b/src/test/test-data/issue-189.unformatted.xml
new file mode 100644
index 0000000..952ff72
--- /dev/null
+++ b/src/test/test-data/issue-189.unformatted.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file