Merge pull request #198 from DotJoshJohnson/release-2.3.1

Release v2.3.1
This commit is contained in:
Josh Johnson 2018-06-15 22:29:25 -04:00 committed by GitHub
commit f2cfe160ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 4 deletions

View file

@ -2,7 +2,7 @@
"name": "xml", "name": "xml",
"displayName": "XML Tools", "displayName": "XML Tools",
"description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code", "description": "XML Formatting, XQuery, and XPath Tools for Visual Studio Code",
"version": "2.3.0", "version": "2.3.1",
"preview": false, "preview": false,
"publisher": "DotJoshJohnson", "publisher": "DotJoshJohnson",
"author": { "author": {

View file

@ -64,7 +64,19 @@ export class XmlTraverser {
} }
getSiblings(node: Node): Node[] { getSiblings(node: Node): Node[] {
return [...this.getChildAttributeArray(<Element>node.parentNode), ...this.getChildElementArray(node.parentNode)]; if (this.isElement(node)) {
return this.getSiblingElements(node);
}
return this.getSiblingAttributes(node);
}
getSiblingAttributes(node: Node): Node[] {
return this.getChildAttributeArray(<Element>node.parentNode);
}
getSiblingElements(node: Node): Node[] {
return this.getChildElementArray(node.parentNode);
} }
hasSimilarSiblings(node: Node): boolean { hasSimilarSiblings(node: Node): boolean {

View file

@ -33,6 +33,7 @@ export class V2XmlFormatter implements XmlFormatter {
let location = Location.Text; let location = Location.Text;
let lastNonTextLocation = Location.Text; // hah let lastNonTextLocation = Location.Text; // hah
let attributeQuote = ""; let attributeQuote = "";
let lineBreakSpree = false;
// NOTE: all "exiting" checks should appear after their associated "entering" checks // NOTE: all "exiting" checks should appear after their associated "entering" checks
for (let i = 0; i < xml.length; i++) { for (let i = 0; i < xml.length; i++) {
@ -44,7 +45,14 @@ export class V2XmlFormatter implements XmlFormatter {
// entering CData // entering CData
if (location === Location.Text && cc === "<" && nc === "!" && nnc === "[") { if (location === Location.Text && cc === "<" && nc === "!" && nnc === "[") {
output += `${this._getIndent(options, indentLevel)}<`; if (pc === ">" && ppc !== "/") {
output += "<";
}
else {
output += `${this._getIndent(options, indentLevel)}<`;
}
location = Location.CData; location = Location.CData;
} }
@ -94,6 +102,8 @@ export class V2XmlFormatter implements XmlFormatter {
} }
else { else {
// removing trailing non-breaking whitespace here prevents endless indentations (issue #193)
output = this._removeTrailingNonBreakingWhitespace(output);
output += `${this._getIndent(options, indentLevel)}<`; output += `${this._getIndent(options, indentLevel)}<`;
} }
@ -176,8 +186,11 @@ export class V2XmlFormatter implements XmlFormatter {
// if the end tag immediately follows a line break, just add an indentation // if the end tag immediately follows a line break, just add an indentation
// if the end tag immediately follows another end tag or a self-closing tag (issue #185), 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. <element>text</element>) // otherwise, this should be treated as a same-line end tag(ex. <element>text</element>)
if (pc === "\n") { if (pc === "\n" || lineBreakSpree) {
// removing trailing non-breaking whitespace here prevents endless indentations (issue #193)
output = this._removeTrailingNonBreakingWhitespace(output);
output += `${this._getIndent(options, indentLevel)}<`; output += `${this._getIndent(options, indentLevel)}<`;
lineBreakSpree = false;
} }
else if (lastNonTextLocation === Location.EndTag) { else if (lastNonTextLocation === Location.EndTag) {
@ -204,6 +217,14 @@ export class V2XmlFormatter implements XmlFormatter {
// Text // Text
else { else {
if (cc === "\n") {
lineBreakSpree = true;
}
else if (lineBreakSpree && /\S/.test(cc)) {
lineBreakSpree = false;
}
output += cc; output += cc;
} }
} }
@ -219,6 +240,10 @@ export class V2XmlFormatter implements XmlFormatter {
return ((options.editorOptions.insertSpaces) ? " ".repeat(options.editorOptions.tabSize) : "\t").repeat(indentLevel); return ((options.editorOptions.insertSpaces) ? " ".repeat(options.editorOptions.tabSize) : "\t").repeat(indentLevel);
} }
private _removeTrailingNonBreakingWhitespace(text: string): string {
return text.replace(/[^\r\n\S]+$/, "");
}
private _sanitizeComments(xml: string): string { private _sanitizeComments(xml: string): string {
let output = ""; let output = "";
let inComment = false; let inComment = false;

View file

@ -80,6 +80,14 @@ describe("V2XmlFormatter", () => {
testFormatter(xmlFormatter, options, "issue-189"); testFormatter(xmlFormatter, options, "issue-189");
}); });
it("should not add extra line breaks before closing tags", () => {
testFormatter(xmlFormatter, options, "issue-193");
});
it("should not add extra whitespace before CDATA", () => {
testFormatter(xmlFormatter, options, "issue-194");
});
}); });
}); });

View file

@ -0,0 +1,12 @@
<xsl:template name="btn-export-excel-pdf">
<div class="row">
<div class="col-md button-wrapper text-center">
<a class="btn btn-outline-info" role="button" href="javascript:template.printToPdf()" target="_blank">
<i class="far fa-file-pdf">&#160;</i> Export to PDF
</a> &#160;
<a class="btn btn-outline-info" role="button" href="javascript:template.exportToExcel()" target="_blank">
<i class="far fa-file-excel">&#160;</i> Export to EXCEL
</a>
</div>
</div>
</xsl:template>

View file

@ -0,0 +1,12 @@
<xsl:template name="btn-export-excel-pdf">
<div class="row">
<div class="col-md button-wrapper text-center">
<a class="btn btn-outline-info" role="button" href="javascript:template.printToPdf()" target="_blank">
<i class="far fa-file-pdf">&#160;</i> Export to PDF
</a> &#160;
<a class="btn btn-outline-info" role="button" href="javascript:template.exportToExcel()" target="_blank">
<i class="far fa-file-excel">&#160;</i> Export to EXCEL
</a>
</div>
</div>
</xsl:template>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<madeup>
<some>
<element>This is ok</element>
<other><![CDATA[Here is my cdata]]></other>
</some>
</madeup>

View file

@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><madeup><some><element>This is ok</element><other><![CDATA[Here is my cdata]]></other></some></madeup>