value = value.replace(/<!-- htmlmin:ignore -->([\s\S]*?)<!-- htmlmin:ignore -->/g, function(match, group1) {
if (!uidIgnore) {
uidIgnore = uniqueId(value);
+ var pattern = new RegExp('^' + uidIgnore + '([0-9]+)$');
+ if (options.ignoreCustomComments) {
+ options.ignoreCustomComments.push(pattern);
+ }
+ else {
+ options.ignoreCustomComments = [pattern];
+ }
}
- var token = '<!--!' + uidIgnore + ignoredMarkupChunks.length + '-->';
+ var token = '<!--' + uidIgnore + ignoredMarkupChunks.length + '-->';
ignoredMarkupChunks.push(group1);
return token;
});
});
}
if (uidIgnore) {
- str = str.replace(new RegExp('<!--!' + uidIgnore + '([0-9]+)-->', 'g'), function(match, index) {
+ str = str.replace(new RegExp('<!--' + uidIgnore + '([0-9]+)-->', 'g'), function(match, index) {
return ignoredMarkupChunks[+index];
});
}
});
QUnit.test('ignore custom comments', function(assert) {
- var input;
+ var input, output;
- input = '<!-- ko if: someExpressionGoesHere --><li>test</li><!-- /ko -->';
+ input = '<!--! test -->';
+ assert.equal(minify(input), input);
+ assert.equal(minify(input, { removeComments: true }), input);
+ assert.equal(minify(input, { ignoreCustomComments: false }), input);
+ assert.equal(minify(input, {
+ removeComments: true,
+ ignoreCustomComments: []
+ }), '');
+ assert.equal(minify(input, {
+ removeComments: true,
+ ignoreCustomComments: false
+ }), '');
+ input = '<!-- htmlmin:ignore -->test<!-- htmlmin:ignore -->';
+ output = 'test';
+ assert.equal(minify(input), output);
+ assert.equal(minify(input, { removeComments: true }), output);
+ assert.equal(minify(input, { ignoreCustomComments: false }), output);
+ assert.equal(minify(input, {
+ removeComments: true,
+ ignoreCustomComments: []
+ }), output);
+ assert.equal(minify(input, {
+ removeComments: true,
+ ignoreCustomComments: false
+ }), output);
+
+ input = '<!-- ko if: someExpressionGoesHere --><li>test</li><!-- /ko -->';
assert.equal(minify(input, {
removeComments: true,
// ignore knockout comments
}), input);
input = '<!--#include virtual="/cgi-bin/counter.pl" -->';
-
assert.equal(minify(input, {
removeComments: true,
// ignore Apache SSI includes