From af2060dc3837c180681766fe3b930e3a1f52fa10 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Tue, 29 May 2018 19:41:42 -0400 Subject: [PATCH] Omit Extraneous Pre-Start Tag Line Breaks Issue: #178 --- src/formatting/formatters/v2-xml-formatter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/formatting/formatters/v2-xml-formatter.ts b/src/formatting/formatters/v2-xml-formatter.ts index 5f31514..647080f 100644 --- a/src/formatting/formatters/v2-xml-formatter.ts +++ b/src/formatting/formatters/v2-xml-formatter.ts @@ -39,6 +39,7 @@ export class V2XmlFormatter implements XmlFormatter { const nc = xml.charAt(i + 1); const nnc = xml.charAt(i + 2); const pc = xml.charAt(i - 1); + const ppc = xml.charAt(i - 2); // entering CData if (location === Location.Text && cc === "<" && nc === "!" && nnc === "[") { @@ -86,7 +87,8 @@ export class V2XmlFormatter implements XmlFormatter { // entering StartTag.StartTagName else if (location === Location.Text && cc === "<" && ["/", "!"].indexOf(nc) === -1) { // if this occurs after another tag, prepend a line break - if (pc === ">") { + // but do not add one if the previous tag was self-closing (it already adds its own) + if (pc === ">" && ppc !== "/") { output += `${options.newLine}${this._getIndent(options, indentLevel)}<`; }