Leaves conditional comments, Knockout.js containerless bindings, and SSIs alone even if removeComments is true. |
_reformatParseTree: function (removeWhiteSpace, removeComments) {
(function processNode(node, isWithinSensitiveTag, canRemoveLeadingWhiteSpace, canRemoveTrailingWhiteSpace) {
var isInBlockLevelContext = isBlockLevelByTagName[node.nodeName.toLowerCase()] || false;
isWithinSensitiveTag = isWithinSensitiveTag || isSensitiveByTagName[node.nodeName.toLowerCase()] || false;
for (var i = 0 ; i < node.childNodes.length ; i += 1) {
var childNode = node.childNodes[i];
if (childNode.nodeType === childNode.ELEMENT_NODE) {
canRemoveLeadingWhiteSpace = processNode(childNode,
isWithinSensitiveTag,
canRemoveLeadingWhiteSpace,
childNode.nextSibling ? childNode.nextSibling.nodeType === childNode.TEXT_NODE && /^[ \t\n\r]/.test(childNode.nextSibling.nodeValue) : canRemoveTrailingWhiteSpace
);
} else if (childNode.nodeType === childNode.COMMENT_NODE) {
if (/^\s*\/?ko\s/.test(childNode.nodeValue)) {
// Knockout.js containerless binding start or end marker. Remove superfluous whitespace if removeWhiteSpace is true:
if (removeWhiteSpace) {
childNode.nodeValue = childNode.nodeValue.replace(/^\s+|\s+$/g, '');
}
} else if (removeComments && !/^#|^\[if|^
|