Skip to content

Commit

Permalink
feat: added preserveComments option
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Reimertz authored and remy committed Dec 31, 2016
1 parent d53c651 commit a41ab78
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function options(args) {
'skip-absolute-urls',
'videos',
'inlinemin',
'preserve-comments',
],
string: [ // options
'encoding',
Expand All @@ -32,6 +33,7 @@ function options(args) {
o: 'videos',
m: 'inlinemin',
H: 'header',
c: 'preserve-comments',
},
});

Expand All @@ -41,6 +43,10 @@ function options(args) {
argv.compressJS = false;
argv.collapseWhitespace = false;
}
if (argv['preserve-comments']) {
argv.preserveComments = true;
}

if (argv['skip-absolute-urls']) {
argv.skipAbsoluteUrls = true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ module.exports = function () {
collapseWhitespace: true,
nosvg: false, // by default, DO compress SVG with SVGO
skipAbsoluteUrls: false,
preserveComments: false,
};
};
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ function main() {

return Promise.all(promises).then(function then() {
var html = '';
inliner.removeComments($(':root')[0], $);

// remove comments
if (!inliner.options.preserveComments) {
inliner.removeComments($(':root')[0], $);
}

// collapse the white space
if (inliner.options.collapseWhitespace) {
$('pre, textarea').each(function () {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/dont-preserve-comments.opts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preserveComments": false
}
1 change: 1 addition & 0 deletions test/fixtures/dont-preserve-comments.result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline script</title> </head> <body> </body> </html>
10 changes: 10 additions & 0 deletions test/fixtures/dont-preserve-comments.src.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>inline script</title>
</head>
<body>
<!-- hello -->
</body>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/preserve-comments.opts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preserveComments": true
}
1 change: 1 addition & 0 deletions test/fixtures/preserve-comments.result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>inline script</title> </head> <body> <!-- hello --> </body> </html>
10 changes: 10 additions & 0 deletions test/fixtures/preserve-comments.src.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>inline script</title>
</head>
<body>
<!-- hello -->
</body>
</html>

0 comments on commit a41ab78

Please sign in to comment.