Merge pull request #106 from DotJoshJohnson/formatter-fixes

v1.9.1
This commit is contained in:
Josh Johnson 2017-06-20 23:53:32 -04:00 committed by GitHub
commit 60cf5e34ce
2 changed files with 17 additions and 7 deletions

View File

@ -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",

View File

@ -60,20 +60,20 @@ export class XmlFormatter {
}
// <elm></elm>
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--;
}
// <elm>
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];
}
// <elm>...</elm>
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 {
}
// <elm />
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;
}