Merge pull request #17 from DotJoshJohnson/wip-1.3.1

WIP 1.3.1
This commit is contained in:
Josh Johnson 2016-01-09 00:38:59 -05:00
commit d58e7a5324
2 changed files with 34 additions and 0 deletions

View File

@ -51,6 +51,10 @@ export function deactivate() {
}
function _handleContextChange(editor: vsc.TextEditor): void {
if (!editor || !editor.document) {
return;
}
switch (editor.document.languageId) {
case 'xquery':
XQueryLintingFeatureProvider.provideXQueryDiagnostics(editor);

View File

@ -119,8 +119,10 @@ export class XmlFormatter {
removeComments = false;
}
xml = this._stripLineBreaks(xml);
xml = (removeComments) ? xml.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g, '') : xml;
xml = xml.replace(/>\s{0,}</g, '><');
xml = xml.replace(/"\s+(?=[^\s]+=)/g, '" ');
return xml;
}
@ -130,6 +132,34 @@ export class XmlFormatter {
return `${this.newLine}${this.indentPattern.repeat(level)}${trailingValue}`;
}
private _stripLineBreaks(xml: string): string {
let output: string = '';
let inTag: boolean = false;
let inTagName: boolean = false;
let inCdata: boolean = false;
let inAttribute: boolean = false;
for (let i = 0; i < xml.length; i++) {
let char: string = xml.charAt(i);
if (char == '!' && (xml.substr(i, 8) == '![CDATA[' || xml.substr(i, 3) == '!--')) {
inCdata = true;
}
else if (char == ']' && (xml.substr(i, 3) == ']]>' || xml.substr(i, 3) == '-->')) {
inCdata = false;
}
else if (char.search(/[\r\n]/g) > -1 && !inCdata) {
continue;
}
output += char;
}
return output;
}
}
export interface IXmlFormatterOptions {