Skip to content

Commit

Permalink
add customFragmentsInScripts option
Browse files Browse the repository at this point in the history
  • Loading branch information
gzzhanghao committed Sep 18, 2016
1 parent 89c2968 commit 647b148
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dist/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -34008,6 +34008,11 @@ function minify(value, options, partialMarkup) {
if (minifyJS) {
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
options.minifyJS = function(text, inline) {
if (options.customFragmentsInScripts === false) {
text = text.replace(uidPattern, function(match, prefix, index) {
return ignoredCustomMarkupChunks[index];
});
}
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
Expand Down
6 changes: 3 additions & 3 deletions dist/htmlminifier.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,11 @@ function minify(value, options, partialMarkup) {
if (minifyJS) {
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
options.minifyJS = function(text, inline) {
if (options.customFragmentsInScripts === false) {
text = text.replace(uidPattern, function(match, prefix, index) {
return ignoredCustomMarkupChunks[index];
});
}
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
});
Expand Down
3 changes: 3 additions & 0 deletions tests/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,9 @@ QUnit.test('Ignore custom fragments', function(assert) {
/\{\{.*?\}\}/g
]
}), output);

input = '<script>(function() { window.global = 1; <% ... %>; b() <% ... %> })()</script>';
assert.equal(minify(input, { minifyJS: true, customFragmentsInScripts: false }), input);
});

QUnit.test('bootstrap\'s span > button > span', function(assert) {
Expand Down

0 comments on commit 647b148

Please sign in to comment.