From: Juriy Zaytsev Date: Thu, 11 Feb 2010 22:30:58 +0000 (-0500) Subject: Slight refactoring. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=571d46e0831448dd99f1d7ac0c109ff910e2e3a1;p=html-minifier.git Slight refactoring. --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index e918b35..8817099 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -29,13 +29,13 @@ } function isConditionalComment(text) { - return /\[if[^]+\]/.test(text); + return (/\[if[^\]]+\]/).test(text); } function canRemoveAttributeQuotes(value) { // http://www.w3.org/TR/html4/intro/sgmltut.html#attributes // avoid \w, which could match unicode in some implementations - return /^[a-zA-Z0-9-._:]+$/.test(value); + return (/^[a-zA-Z0-9-._:]+$/).test(value); } function attributesInclude(attributes, attribute) { @@ -73,7 +73,7 @@ } function isBooleanAttribute(attrName) { - return /^(?:checked|disabled|selected|readonly)$/.test(attrName); + return (/^(?:checked|disabled|selected|readonly)$/).test(attrName); } function cleanAttributeValue(tag, attrName, attrValue) { @@ -87,6 +87,18 @@ return attrValue; } + function removeCDATASections(text) { + return text + // "/* */" or "// ]]>" + .replace(/(?:\/\*\s*\]\]>\s*\*\/|\/\/\s*\]\]>)\s*$/, ''); + } + + function removeComments(text) { + return text.replace(/^\s*\s*$/, ''); + } + var reEmptyAttribute = new RegExp( '^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(' + '?:down|up|over|move|out)|key(?:press|down|up)))$'); @@ -94,7 +106,6 @@ function canDeleteEmptyAttribute(tag, attrName, attrValue) { var isValueEmpty = /^(["'])?\s*\1$/.test(attrValue); if (isValueEmpty) { - log('empty attribute: ' + tag + ' :: ' + attrName); return ( (tag === 'input' && attrName === 'value') || reEmptyAttribute.test(attrName)); @@ -188,14 +199,10 @@ chars: function( text ) { if (currentTag === 'script' || currentTag === 'style') { if (options.removeCommentsFromCDATA) { - text = text.replace(/^\s*\s*$/, ''); + text = removeComments(text); } if (options.removeCDATASectionsFromCDATA) { - text = text - // "/* */" or "// ]]>" - .replace(/(?:\/\*\s*\]\]>\s*\*\/|\/\/\s*\]\]>)\s*$/, ''); + text = removeCDATASections(text); } } if (options.collapseWhitespace) {