Skip to content

Commit

Permalink
move chunk index within comment
Browse files Browse the repository at this point in the history
fixes #572
  • Loading branch information
alexlamsl committed Mar 21, 2016
1 parent e74f603 commit 13130d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
32 changes: 19 additions & 13 deletions dist/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,17 +1176,13 @@
return text;
}

function getModule(name, path) {
var minifyURLs = (function() {
// try to get global reference first
var result = global[name];
if (typeof result === 'undefined' && typeof require === 'function') {
result = require(path);
var RelateUrl = global.RelateUrl;
if (typeof RelateUrl === 'undefined' && typeof require === 'function') {
RelateUrl = require('relateurl');
}
return result;
}

var minifyURLs = (function() {
var RelateUrl = getModule('RelateUrl', 'relateurl');
if (RelateUrl && RelateUrl.relate) {
return function(text, options) {
try {
Expand All @@ -1204,7 +1200,12 @@
})();

var minifyJS = (function() {
var UglifyJS = getModule('UglifyJS', 'uglify-js');
// try to get global reference first
var UglifyJS = global.UglifyJS;
if (typeof UglifyJS === 'undefined' && typeof require === 'function') {
UglifyJS = require('uglify-js');
}

if (UglifyJS && UglifyJS.minify) {
return function(text, options) {
try {
Expand All @@ -1222,7 +1223,12 @@
})();

var minifyCSS = (function() {
var CleanCSS = getModule('CleanCSS', 'clean-css');
// try to get global reference first
var CleanCSS = global.CleanCSS;
if (typeof CleanCSS === 'undefined' && typeof require === 'function') {
CleanCSS = require('clean-css');
}

if (CleanCSS) {
return function(text, options, inline) {
try {
Expand Down Expand Up @@ -1282,9 +1288,9 @@
// completely-horribly-broken-alien-non-html-emoj-cthulhu-filled content
value = value.replace(/<!-- htmlmin:ignore -->([\s\S]*?)<!-- htmlmin:ignore -->/g, function(match, group1) {
if (!uidIgnore) {
uidIgnore = '<!--!' + uniqueId(value) + '-->';
uidIgnore = uniqueId(value);
}
var token = uidIgnore + ignoredMarkupChunks.length;
var token = '<!--!' + uidIgnore + ignoredMarkupChunks.length + '-->';
ignoredMarkupChunks.push(group1);
return token;
});
Expand Down Expand Up @@ -1657,7 +1663,7 @@
});
}
if (uidIgnore) {
str = str.replace(new RegExp(uidIgnore + '([0-9]+)', 'g'), function(match, index) {
str = str.replace(new RegExp('<!--!' + uidIgnore + '([0-9]+)-->', 'g'), function(match, index) {
return ignoredMarkupChunks[+index];
});
}
Expand Down
Loading

0 comments on commit 13130d7

Please sign in to comment.