diff --git a/package.json b/package.json
index f4839b3..2bea686 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": "1.9.0",
+ "version": "1.9.1",
"publisher": "DotJoshJohnson",
"author": {
"name": "Josh Johnson",
diff --git a/src/services/XmlFormatter.ts b/src/services/XmlFormatter.ts
index a1aac00..6f4e314 100644
--- a/src/services/XmlFormatter.ts
+++ b/src/services/XmlFormatter.ts
@@ -60,20 +60,20 @@ export class XmlFormatter {
}
//
- else if (/^<\w/.test(parts[i - 1]) && /^<\/\w/.test(parts[i])
- && /^<[\w:\-\.\,]+/.exec(parts[i - 1])[0] == /^<\/[\w:\-\.\,]+/.exec(parts[i])[0].replace('/', '')) {
+ else if (/^<(\w|:)/.test(parts[i - 1]) && /^<\/(\w|:)/.test(parts[i])
+ && /^<[\w:\-\.\,\/ ]+/.exec(parts[i - 1])[0] == /^<\/[\w:\-\.\, ]+/.exec(parts[i])[0].replace('/', '')) {
output += parts[i];
if (!inComment) level--;
}
//
- else if (parts[i].search(/<\w/) > -1 && parts[i].search(/<\//) == -1 && parts[i].search(/\/>/) == -1) {
+ else if (parts[i].search(/<(\w|:)/) > -1 && parts[i].search(/<\//) == -1 && parts[i].search(/\/>/) == -1) {
output = (!inComment) ? output += this._getIndent(level++, parts[i]) : output += parts[i];
}
// ...
- else if (parts[i].search(/<\w/) > -1 && parts[i].search(/<\//) > -1) {
+ else if (parts[i].search(/<(\w|:)/) > -1 && parts[i].search(/<\//) > -1) {
output = (!inComment) ? output += this._getIndent(level, parts[i]) : output += parts[i];
}
@@ -83,12 +83,12 @@ export class XmlFormatter {
}
//
- else if (parts[i].search(/\/>/) > -1 && (!this.splitNamespaces || parts[i].search(/xmlns\:/) == -1)) {
+ else if (parts[i].search(/\/>/) > -1 && (!this.splitNamespaces || parts[i].search(/xmlns(:|=)/) == -1)) {
output = (!inComment) ? output += this._getIndent(level, parts[i]) : output += parts[i];
}
// xmlns />
- else if (parts[i].search(/\/>/) > -1 && parts[i].search(/xmlns\:/) > -1 && this.splitNamespaces) {
+ else if (parts[i].search(/\/>/) > -1 && parts[i].search(/xmlns(:|=)/) > -1 && this.splitNamespaces) {
output = (!inComment) ? output += this._getIndent(level--, parts[i]) : output += parts[i];
}
@@ -152,6 +152,8 @@ export class XmlFormatter {
for (let i = 0; i < xml.length; i++) {
let char: string = xml.charAt(i);
+ let prev: string = xml.charAt(i - 1);
+ let next: string = xml.charAt(i + 1);
if (char == '!' && (xml.substr(i, 8) == '![CDATA[' || xml.substr(i, 3) == '!--')) {
inCdata = true;
@@ -166,6 +168,14 @@ export class XmlFormatter {
}
else if (char.search(/[\r\n]/g) > -1 && !inCdata) {
+ if (/\r/.test(char) && /\S|\r|\n/.test(prev) && /\S|\r|\n/.test(xml.charAt(i + this.newLine.length))) {
+ output += char;
+ }
+
+ else if (/\n/.test(char) && /\S|\r|\n/.test(xml.charAt(i - this.newLine.length)) && /\S|\r|\n/.test(next)) {
+ output += char;
+ }
+
continue;
}