Skip to content

Commit 647b148

Browse files
committed
add customFragmentsInScripts option
1 parent 89c2968 commit 647b148

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

dist/htmlminifier.js

+5
Original file line numberDiff line numberDiff line change
@@ -34008,6 +34008,11 @@ function minify(value, options, partialMarkup) {
3400834008
if (minifyJS) {
3400934009
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
3401034010
options.minifyJS = function(text, inline) {
34011+
if (options.customFragmentsInScripts === false) {
34012+
text = text.replace(uidPattern, function(match, prefix, index) {
34013+
return ignoredCustomMarkupChunks[index];
34014+
});
34015+
}
3401134016
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
3401234017
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
3401334018
});

dist/htmlminifier.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/htmlminifier.js

+5
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,11 @@ function minify(value, options, partialMarkup) {
880880
if (minifyJS) {
881881
var pattern = new RegExp('(\\\\t|)' + uidAttr + '([0-9]+)(\\\\t|)', 'g');
882882
options.minifyJS = function(text, inline) {
883+
if (options.customFragmentsInScripts === false) {
884+
text = text.replace(uidPattern, function(match, prefix, index) {
885+
return ignoredCustomMarkupChunks[index];
886+
});
887+
}
883888
return minifyJS(text, inline).replace(pattern, function(match, prefix, index, suffix) {
884889
return (prefix && '\t') + uidAttr + index + (suffix && '\t');
885890
});

tests/minifier.js

+3
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,9 @@ QUnit.test('Ignore custom fragments', function(assert) {
17461746
/\{\{.*?\}\}/g
17471747
]
17481748
}), output);
1749+
1750+
input = '<script>(function() { window.global = 1; <% ... %>; b() <% ... %> })()</script>';
1751+
assert.equal(minify(input, { minifyJS: true, customFragmentsInScripts: false }), input);
17491752
});
17501753

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

0 commit comments

Comments
 (0)