From b75a4207b56abd8d0f6fda7057e1ff45144d92e0 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 20 Apr 2016 19:24:50 +0800 Subject: [PATCH] simplify default values --- README.md | 2 +- src/htmlminifier.js | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 37c2fe9..112df4f 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe | `customEventAttributes` | Arrays of regex'es that allow to support custom event attributes for `minifyJS` (e.g. `ng-click`) | `[ /^on[a-z]{3,}$/ ]` | | `decodeEntities` | Use direct Unicode characters whenever possible | `false` | | `html5` | Parse input according to HTML5 specifications | `true` | -| `ignoreCustomComments` | Array of regex'es that allow to ignore certain comments, when matched | `[ ]` | +| `ignoreCustomComments` | Array of regex'es that allow to ignore certain comments, when matched | `[ /^!/ ]` | | `ignoreCustomFragments` | Array of regex'es that allow to ignore certain fragments, when matched (e.g. ``, `{{ ... }}`, etc.) | `[ /<%[\s\S]*?%>/, /<\?[\s\S]*?\?>/ ]` | | `includeAutoGeneratedTags` | Insert tags generated by HTML parser | `true` | | `keepClosingSlash` | Keep the trailing slash on singleton elements | `false` | diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 3f0fb90..1efb08e 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -82,18 +82,11 @@ function isConditionalComment(text) { } function isIgnoredComment(text, options) { - if (/^!/.test(text)) { - return true; - } - - if (options.ignoreCustomComments) { - for (var i = 0, len = options.ignoreCustomComments.length; i < len; i++) { - if (options.ignoreCustomComments[i].test(text)) { - return true; - } + for (var i = 0, len = options.ignoreCustomComments.length; i < len; i++) { + if (options.ignoreCustomComments[i].test(text)) { + return true; } } - return false; } @@ -624,6 +617,17 @@ function processOptions(options) { } } + if (!('ignoreCustomComments' in options)) { + options.ignoreCustomComments = [/^!/]; + } + + if (!('ignoreCustomFragments' in options)) { + options.ignoreCustomFragments = [ + /<%[\s\S]*?%>/, + /<\?[\s\S]*?\?>/ + ]; + } + if (options.minifyURLs && typeof options.minifyURLs !== 'object') { options.minifyURLs = {}; } @@ -822,10 +826,7 @@ function minify(value, options, partialMarkup) { return token; }); - var customFragments = (options.ignoreCustomFragments || [ - /<%[\s\S]*?%>/, - /<\?[\s\S]*?\?>/ - ]).map(function(re) { + var customFragments = options.ignoreCustomFragments.map(function(re) { return re.source; }); if (customFragments.length) { -- 2.34.1