isIgnoring = false,
t = new Date();
+ if (options.removeIgnored) {
+ value = value
+ .replace(/<\?[^\?]+\?>/g, '')
+ .replace(/<%[^%]+%>/g, '');
+ }
+
function _canCollapseWhitespace(tag, attrs) {
return canCollapseWhitespace(tag) || options.canCollapseWhitespace(tag, attrs);
}
}
buffer.push(text);
},
- ignore: function(text) {
- // `text` === strings that start with `<?` or `<%` and end with `?>` or `%>`.
- buffer.push(options.removeIgnored ? '' : text); // `text` allowed by default.
- },
doctype: function(doctype) {
buffer.push(options.useShortDoctype ? '<!DOCTYPE html>' : collapseWhitespace(doctype));
},
startTagClose = /\s*(\/?)>/,
endTag = /^<\/([\w:-]+)[^>]*>/,
endingSlash = /\/>$/,
- doctype = /^<!DOCTYPE [^>]+>/i,
- startIgnore = /<(%|\?)/,
- endIgnore = /(%|\?)>/;
+ doctype = /^<!DOCTYPE [^>]+>/i;
var IS_REGEX_CAPTURING_BROKEN = false;
'x'.replace(/x(.)?/g, function(m, g) {
}
// Ignored elements?
- else if (html.search(startIgnore) === 0) {
- index = html.search(endIgnore); // Find closing tag.
- if (index >= 0) { // Found?
- // @TODO: Pass matched open/close tags back to handler.
- handler.ignore && handler.ignore(html.substring(0, index + 2)); // Return ignored string if callback exists.
- html = html.substring(index + 2); // Next starting point for parser.
- chars = false; // Chars flag.
+ else if ( /^<\?/.test( html ) ) {
+ index = html.indexOf( '?>', 2 );
+ if ( index >= 0 ) {
+ if ( handler.chars ) {
+ handler.chars( html.substring( 0, index + 2 ) );
+ }
+ html = html.substring( index + 2 );
+ }
+ }
+
+ else if ( /^<%/.test( html ) ) {
+ index = html.indexOf( '%>', 2 );
+ if ( index >= 0 ) {
+ if ( handler.chars ) {
+ handler.chars(html.substring( 0, index + 2) );
+ }
+ html = html.substring( index + 2 );
}
}
output = 'This is the start.<% ... %><%= ... %><? ... ?>No comment, but middle.<?= ... ?><?php ... ?><?xml ... ?>Hello, this is the end!';
equal(minify(input, {}), input);
equal(minify(input, { removeComments: true, collapseWhitespace: true }), output);
- output = 'This is the start.No comment, but middle.Hello, this is the end!';
+ output = 'This is the start.No comment, but middle. Hello, this is the end!';
equal(minify(input, { removeComments: true, collapseWhitespace: true, removeIgnored: true }), output);
input = '<% if foo? %>\r\n <div class="bar">\r\n ...\r\n </div>\r\n<% end %>';
output = '<div class="bar">...</div>';
equal(minify(input, { collapseWhitespace: true, removeIgnored: true }), output);
+ input = '<a class="<% if foo? %>bar<% end %>"></a>';
+ equal(minify(input, {}), input);
+ output = '<a class="bar"></a>';
+ equal(minify(input, { removeIgnored: true }), output);
});
test('bootstrap\'s span > button > span', function() {