| `includeAutoGeneratedTags` | Insert tags generated by HTML parser | `true` |
| `keepClosingSlash` | Keep the trailing slash on singleton elements | `false` |
| `maxLineLength` | Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points |
-| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |
+| `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/jakubpawlowicz/clean-css)) | `false` (could be `true`, `Object`, `Function(text)`) |
| `minifyJS` | Minify JavaScript in script elements and event attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `Object`, `Function(text, inline)`) |
| `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `String`, `Object`, `Function(text)`) |
| `preserveLineBreaks` | Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with `collapseWhitespace=true` | `false` |
}
else if (attrName === 'style') {
attrValue = trimWhitespace(attrValue);
- if (attrValue && /;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
- attrValue = attrValue.replace(/\s*;$/, '');
+ if (attrValue) {
+ if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) {
+ attrValue = attrValue.replace(/\s*;$/, '');
+ }
+ attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue)));
}
- return options.minifyCSS(attrValue, true);
+ return attrValue;
}
else if (isSrcset(attrName, tag)) {
// https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-srcset
// Wrap CSS declarations for CleanCSS > 3.x
// See https://github.com/jakubpawlowicz/clean-css/issues/418
-function wrapCSS(text) {
+function wrapInlineCSS(text) {
return '*{' + text + '}';
}
-function unwrapCSS(text) {
- var matches = text.match(/^\*\{([\s\S]*)\}$/m);
- if (matches && matches[1]) {
- return matches[1];
- }
- return text;
+function unwrapInlineCSS(text) {
+ var matches = text.match(/^\*\{([\s\S]*)\}$/);
+ return matches ? matches[1] : text;
}
function cleanConditionalComment(comment, options) {
if (typeof minifyCSS.advanced === 'undefined') {
minifyCSS.advanced = false;
}
- options.minifyCSS = function(text, inline) {
+ options.minifyCSS = function(text) {
text = text.replace(/(url\s*\(\s*)("|'|)(.*?)\2(\s*\))/ig, function(match, prefix, quote, url, suffix) {
return prefix + quote + options.minifyURLs(url) + quote + suffix;
});
var start = text.match(/^\s*<!--/);
var style = start ? text.slice(start[0].length).replace(/-->\s*$/, '') : text;
try {
- var cleanCSS = new CleanCSS(minifyCSS);
- if (inline) {
- return unwrapCSS(cleanCSS.minify(wrapCSS(style)).styles);
- }
- return cleanCSS.minify(style).styles;
+ return new CleanCSS(minifyCSS).minify(style).styles;
}
catch (err) {
options.log(err);
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
var minifyCSS = options.minifyCSS;
if (minifyCSS) {
- options.minifyCSS = function(text, inline) {
- return minifyCSS(text, inline).replace(uidPattern, function(match, prefix, index, suffix) {
+ options.minifyCSS = function(text) {
+ return minifyCSS(text).replace(uidPattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
};
QUnit.test('custom processors', function(assert) {
var input, output;
- function css(text, inline) {
- return inline ? 'Inline CSS' : 'Normal CSS';
+ function css() {
+ return 'Some CSS';
}
input = '<style>\n.foo { font: 12pt "bar" } </style>';
assert.equal(minify(input), input);
assert.equal(minify(input, { minifyCSS: null }), input);
assert.equal(minify(input, { minifyCSS: false }), input);
- output = '<style>Normal CSS</style>';
+ output = '<style>Some CSS</style>';
assert.equal(minify(input, { minifyCSS: css }), output);
input = '<p style="font: 12pt \'bar\'"></p>';
assert.equal(minify(input), input);
assert.equal(minify(input, { minifyCSS: null }), input);
assert.equal(minify(input, { minifyCSS: false }), input);
- output = '<p style="Inline CSS"></p>';
+ output = '<p style="Some CSS"></p>';
assert.equal(minify(input, { minifyCSS: css }), output);
function js(text, inline) {