forked from external/vscode-xml
		
	Merge pull request #198 from DotJoshJohnson/release-2.3.1
Release v2.3.1
This commit is contained in:
		
						commit
						f2cfe160ba
					
				
					 8 changed files with 81 additions and 4 deletions
				
			
		| 
						 | 
					@ -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": {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 === "[") {
 | 
				
			||||||
 | 
					                if (pc === ">" && ppc !== "/") {
 | 
				
			||||||
 | 
					                    output += "<";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
                    output += `${this._getIndent(options, indentLevel)}<`;
 | 
					                    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;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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");
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/test/test-data/issue-193.formatted.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/test/test-data/issue-193.formatted.xml
									
										
									
									
									
										Normal 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"> </i> Export to PDF                                        
 | 
				
			||||||
 | 
					            </a>                                                                           
 | 
				
			||||||
 | 
					            <a class="btn btn-outline-info" role="button" href="javascript:template.exportToExcel()" target="_blank">
 | 
				
			||||||
 | 
					                <i class="far fa-file-excel"> </i> Export to EXCEL                                        
 | 
				
			||||||
 | 
					            </a>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</xsl:template>
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/test/test-data/issue-193.unformatted.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/test/test-data/issue-193.unformatted.xml
									
										
									
									
									
										Normal 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"> </i> Export to PDF                                        
 | 
				
			||||||
 | 
					        </a>                                                                           
 | 
				
			||||||
 | 
					        <a class="btn btn-outline-info" role="button" href="javascript:template.exportToExcel()" target="_blank">
 | 
				
			||||||
 | 
					          <i class="far fa-file-excel"> </i> Export to EXCEL                                        
 | 
				
			||||||
 | 
					        </a>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  </xsl:template>
 | 
				
			||||||
							
								
								
									
										7
									
								
								src/test/test-data/issue-194.formatted.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/test/test-data/issue-194.formatted.xml
									
										
									
									
									
										Normal 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>
 | 
				
			||||||
							
								
								
									
										1
									
								
								src/test/test-data/issue-194.unformatted.xml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/test/test-data/issue-194.unformatted.xml
									
										
									
									
									
										Normal 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>
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue