Merge pull request #19 from DotJoshJohnson/wip-1.3.2

Fix #18
This commit is contained in:
Josh Johnson 2016-01-09 12:29:49 -05:00
commit 708250157f

View File

@ -119,10 +119,15 @@ export class XmlFormatter {
removeComments = false; removeComments = false;
} }
xml = this._stripLineBreaks(xml); xml = this._stripLineBreaks(xml); // all line breaks outside of CDATA elements
xml = (removeComments) ? xml.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g, '') : xml; xml = (removeComments) ? xml.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g, '') : xml;
xml = xml.replace(/>\s{0,}</g, '><'); xml = xml.replace(/>\s{0,}</g, '><'); // insignificant whitespace between tags
xml = xml.replace(/"\s+(?=[^\s]+=)/g, '" '); 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; return xml;
} }