diff --git a/src/services/XmlFormatter.ts b/src/services/XmlFormatter.ts index a615acd..85ad7a3 100644 --- a/src/services/XmlFormatter.ts +++ b/src/services/XmlFormatter.ts @@ -119,10 +119,15 @@ export class XmlFormatter { removeComments = false; } - xml = this._stripLineBreaks(xml); + xml = this._stripLineBreaks(xml); // all line breaks outside of CDATA elements xml = (removeComments) ? xml.replace(/\/g, '') : xml; - xml = xml.replace(/>\s{0,}<'); - xml = xml.replace(/"\s+(?=[^\s]+=)/g, '" '); + xml = xml.replace(/>\s{0,}<'); // insignificant whitespace between tags + xml = xml.replace(/"\s+(?=[^\s]+=)/g, '" '); // spaces between attributes + xml = xml.replace(/"\s+(?=>)/g, '"'); // spaces between the last attribute and tag close (>) + xml = xml.replace(/"\s+(?=\/>)/g, '" '); // spaces between the last attribute and tag close (/>) + xml = xml.replace(/[^ <>="]\s+[^ <>="]+=/g, (match: string) => { // spaces between the node name and the first attribute + return match.replace(/\s+/g, ' '); + }); return xml; }