Eliminate Extra Line Breaks
This only solves half of the problem. Issue: #193
This commit is contained in:
		
							parent
							
								
									69a7a9164b
								
							
						
					
					
						commit
						a99ba2ea41
					
				
					 1 changed files with 11 additions and 1 deletions
				
			
		| 
						 | 
					@ -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++) {
 | 
				
			||||||
| 
						 | 
					@ -176,8 +177,9 @@ 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) {
 | 
				
			||||||
                    output += `${this._getIndent(options, indentLevel)}<`;
 | 
					                    output += `${this._getIndent(options, indentLevel)}<`;
 | 
				
			||||||
 | 
					                    lineBreakSpree = false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                else if (lastNonTextLocation === Location.EndTag) {
 | 
					                else if (lastNonTextLocation === Location.EndTag) {
 | 
				
			||||||
| 
						 | 
					@ -204,6 +206,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;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue