From d36a358d368747b9e86a6ee6ff37dbb55f2500e8 Mon Sep 17 00:00:00 2001 From: Micky Hulse Date: Wed, 21 Aug 2013 14:21:35 -0700 Subject: [PATCH] Simplified regex ... For finding start and end "ignored" tags. --- dist/all.js | 10 ++++++---- src/htmlminifier.js | 2 +- src/htmlparser.js | 8 +++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dist/all.js b/dist/all.js index aa7f6d8..21c7de5 100644 --- a/dist/all.js +++ b/dist/all.js @@ -30,7 +30,9 @@ var startTag = /^<([\w:-]+)((?:\s*[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/, endTag = /^<\/([\w:-]+)[^>]*>/, attr = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g, - doctype = /^]+>/i; + doctype = /^]+>/i, + startIgnore = /<(%|\?)/; + endIgnore = /(%|\?)>/; // Empty Elements - HTML 4.01 var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"); @@ -78,8 +80,8 @@ } // Ignored elements? - else if ((ignored[1] = (html.indexOf('<%') === 0)) || (ignored[2] = (html.indexOf('' : '?>'); // Find closing tag. + else if (html.search(startIgnore) === 0) { + index = html.search(endIgnore); // Find closing tag. if (index >= 0) { // Found? handler.ignore && handler.ignore(html.substring(0, index + 2)); // Return ignored string if callback exists. html = html.substring(index + 2); // Next starting point for parser. @@ -777,7 +779,7 @@ }, ignore: function(text) { // `text` === strings that start with `` or `%>`. - buffer.push(options.removeIgnored ? '' : trimWhitespace(text)); // `text` allowed by default. + buffer.push(options.removeIgnored ? '' : text); // `text` allowed by default. }, doctype: function(doctype) { buffer.push(options.useShortDoctype ? '' : collapseWhitespace(doctype)); diff --git a/src/htmlminifier.js b/src/htmlminifier.js index c0dbccb..1ae1a35 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -416,7 +416,7 @@ }, ignore: function(text) { // `text` === strings that start with `` or `%>`. - buffer.push(options.removeIgnored ? '' : trimWhitespace(text)); // `text` allowed by default. + buffer.push(options.removeIgnored ? '' : text); // `text` allowed by default. }, doctype: function(doctype) { buffer.push(options.useShortDoctype ? '' : collapseWhitespace(doctype)); diff --git a/src/htmlparser.js b/src/htmlparser.js index 28aaf1d..c6b81dd 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -30,7 +30,9 @@ var startTag = /^<([\w:-]+)((?:\s*[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/, endTag = /^<\/([\w:-]+)[^>]*>/, attr = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g, - doctype = /^]+>/i; + doctype = /^]+>/i, + startIgnore = /<(%|\?)/; + endIgnore = /(%|\?)>/; // Empty Elements - HTML 4.01 var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"); @@ -78,8 +80,8 @@ } // Ignored elements? - else if ((ignored[1] = (html.indexOf('<%') === 0)) || (ignored[2] = (html.indexOf('' : '?>'); // Find closing tag. + else if (html.search(startIgnore) === 0) { + index = html.search(endIgnore); // Find closing tag. if (index >= 0) { // Found? handler.ignore && handler.ignore(html.substring(0, index + 2)); // Return ignored string if callback exists. html = html.substring(index + 2); // Next starting point for parser. -- 2.34.1