From f88c1d438419109ef9c0bc01f07830e789b0aba9 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Sat, 9 Jan 2016 12:27:35 -0500 Subject: [PATCH] Fix #18 --- src/services/XmlFormatter.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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; }