From: Andreas Lind Date: Mon, 22 May 2017 10:19:28 +0000 (+0200) Subject: Add the ability for options.can{Trim,Collapse}Whitespace to veto the default implemen... X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=67d608fece5ffa0bd826effd04efa7fb335b4da7;p=html-minifier.git Add the ability for options.can{Trim,Collapse}Whitespace to veto the default implementation when that returns true. Also, provide the default implementation as the 3rd parameter to the custom hook so the user doesn't have to reimplement it. --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index db2c56a..5b9c9cf 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -626,13 +626,11 @@ function processOptions(options) { options.log = identity; } - var defaultTesters = ['canCollapseWhitespace', 'canTrimWhitespace']; - for (var i = 0, len = defaultTesters.length; i < len; i++) { - if (!options[defaultTesters[i]]) { - options[defaultTesters[i]] = function() { - return false; - }; - } + if (!options.canCollapseWhitespace) { + options.canCollapseWhitespace = canCollapseWhitespace; + } + if (!options.canTrimWhitespace) { + options.canTrimWhitespace = canTrimWhitespace; } if (!('ignoreCustomComments' in options)) { @@ -894,11 +892,11 @@ function minify(value, options, partialMarkup) { } function _canCollapseWhitespace(tag, attrs) { - return canCollapseWhitespace(tag) || options.canCollapseWhitespace(tag, attrs); + return options.canCollapseWhitespace(tag, attrs, canCollapseWhitespace); } function _canTrimWhitespace(tag, attrs) { - return canTrimWhitespace(tag) || options.canTrimWhitespace(tag, attrs); + return options.canTrimWhitespace(tag, attrs, canTrimWhitespace); } function removeStartTag() {