!function (UglifyJS, path, util, extend) {
    'use strict';

    var number = util.number,
        replaceMultiple = util.regexp.replaceMultiple,
        time = util.time;

    module.exports = function (inputs, outputs, args, callback) {
        if (arguments.length === 3) {
            callback = arguments[2];
            args = null;
        }

        args || (args = {});

        var that = this;

        inputs.deleted.forEach(function (filename) {
            outputs[filename] = null;
        });

        inputs = inputs.newOrChanged;

        Object.getOwnPropertyNames(inputs).forEach(function (filename) {
            var startTime = Date.now(),
                original = inputs[filename],
                extname = (path.extname(filename) || '').toLowerCase(),
                perFileArgs = extend(true, {}, args),
                minified;

            if (extname === '.html' || extname === '.htm') {
                minified = outputs[filename] = new Buffer(processHTML(original.toString()));
            } else if (extname === '.js') {
                var sourceMap;

                if (perFileArgs.map) {
                    sourceMap = UglifyJS.SourceMap(extend({}, perFileArgs.map, { file: filename }));
                    perFileArgs = extend(true, {}, perFileArgs, { output: { source_map: sourceMap } });

                    delete perFileArgs.map;
                }

                var uglified = UglifyJS.minify(removeDebugCode(original.toString()), extend({ fromString: true }, perFileArgs));

                minified = outputs[filename] = uglified.code;

                if (sourceMap) {
                    outputs[filename + '.map'] = sourceMap.toString();
                }
            } else {
                outputs[filename] = original;

                return;
            }

            that.log([
                'Uglified ',
                filename,
                ', took ',
                time.humanize(Date.now() - startTime),
                ' (',
                number.bytes(original.length),
                ' -> ',
                number.bytes(minified.length),
                ', ',
                (((minified.length / original.length) - 1) * 100).toFixed(1),
                '%)'
            ].join(''));
        });

        callback(null, outputs);
    };

    function processHTML(text) {
        var pattern = /(<script [^>]*?type="text\/javascript"[^>]*>)([\s\S]*?)(<\/script>)/gmi;

        return replaceMultiple(
            text,
            [
                [
                    /(<script [^>]*?type="text\/javascript"[^>]*>)([\s\S]*?)(<\/script>)/gmi,
                    function (match0, match1, match2, match3, index, input) {
                        return match1 + UglifyJS.minify(removeDebugCode(match2), { fromString: true }).code + match3;
                    }
                ]
            ]
        );
    }

    function removeDebugCode(code) {
        var output = [],
            count = 0,
            startPattern = /\/\/\s*IF\s+DEBUG(\s|$)/,
            endPattern = /\/\/\s*END\s+DEBUG(\s|$)/;

        code.split('\n').forEach(function (line) {
            if (count) {
                if (endPattern.test(line)) {
                    count--;
                }
            } else {
                var startMatch = startPattern.exec(line);

                if (startMatch) {
                    output.push(line.substr(0, startMatch.index));
                    count++;
                } else {
                    output.push(line + '\n');
                }
            }
        });

        return output.join('');
    }
}(
    require('uglify-js'),
    require('path'),
    require('publishjs').util,
    require('node.extend')
);
@@ -3063,24 +3063,25 @@
 %5C/%5Cs*END
+(
 %5Cs+DEBUG
 (%5Cs%7C$)/;
@@ -3068,24 +3068,26 @@
 END(%5Cs+DEBUG
+)?
 (%5Cs%7C$)/;%0A%0A  
@@ -3151,20 +3151,49 @@
     
-if (count) %7B
+var startMatch = startPattern.test(line),
 %0A   
@@ -3205,20 +3205,27 @@
         
-if (
+endMatch = 
 endPatte
@@ -3241,59 +3241,148 @@
 ine)
-) %7B%0A                    count--;%0A                %7D%0A
+;%0A%0A            if (startMatch && endMatch) %7B%0A                if (startMatch.index %3C endMatch.index) %7B%0A                    endMatch = 0;%0A    
     
@@ -3406,35 +3406,35 @@
                 
-var
+   
  startMatch = st
@@ -3435,38 +3435,44 @@
 h = 
-startPattern.exec(line);%0A%0A    
+0;%0A                %7D%0A            %7D%0A%0A
     
@@ -3489,36 +3489,32 @@
  (startMatch) %7B%0A
-    
                 
@@ -3572,28 +3572,24 @@
             
-    
 count++;%0A   
@@ -3597,33 +3597,85 @@
         
-  
-  
 %7D else
+ if (endMatch)
  %7B%0A    
+            count--;%0A            %7D else %7B%0A
         
@@ -3708,34 +3708,16 @@
  '%5Cn');%0A
-                %7D%0A
         

Fix END without DEBUG condition