Prevent Endless Indentation

Issue: #193
This commit is contained in:
Josh Johnson 2018-06-12 21:05:02 -04:00
parent a99ba2ea41
commit 97afac0031
1 changed files with 8 additions and 0 deletions

View File

@ -95,6 +95,8 @@ export class V2XmlFormatter implements XmlFormatter {
}
else {
// removing trailing non-breaking whitespace here prevents endless indentations (issue #193)
output = this._removeTrailingNonBreakingWhitespace(output);
output += `${this._getIndent(options, indentLevel)}<`;
}
@ -178,6 +180,8 @@ export class V2XmlFormatter implements XmlFormatter {
// 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>)
if (pc === "\n" || lineBreakSpree) {
// removing trailing non-breaking whitespace here prevents endless indentations (issue #193)
output = this._removeTrailingNonBreakingWhitespace(output);
output += `${this._getIndent(options, indentLevel)}<`;
lineBreakSpree = false;
}
@ -229,6 +233,10 @@ export class V2XmlFormatter implements XmlFormatter {
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 {
let output = "";
let inComment = false;