From: Micky Hulse Date: Wed, 21 Aug 2013 10:15:34 +0000 (-0700) Subject: New feature: "ignored" tags. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=37dfc4fc7d89ae4564fb3904bca3316110b6c89e;p=html-minifier.git New feature: "ignored" tags. Still a work in progress. --- diff --git a/dist/all.js b/dist/all.js index 5333f9a..aa7f6d8 100644 --- a/dist/all.js +++ b/dist/all.js @@ -54,7 +54,7 @@ var reCache = { }, stackedTag, reStackedTag, tagMatch; var HTMLParser = global.HTMLParser = function( html, handler ) { - var index, chars, match, stack = [], last = html, prevTag, nextTag; + var index, chars, ignored = [], match, stack = [], last = html, prevTag, nextTag; stack.last = function(){ return this[ this.length - 1 ]; }; @@ -76,6 +76,17 @@ chars = false; } } + + // Ignored elements? + else if ((ignored[1] = (html.indexOf('<%') === 0)) || (ignored[2] = (html.indexOf('' : '?>'); // 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. + chars = false; // Chars flag. + } + } + else if ( (match = doctype.exec( html )) ) { if ( handler.doctype ) handler.doctype( match[0] ); @@ -238,6 +249,9 @@ }, comment: function( text ) { results += ""; + }, + ignore: function(text) { + // Need to test this. } }); @@ -327,6 +341,9 @@ }, comment: function( /*text*/ ) { // create comment node + }, + ignore: function(text) { + // Need to test this. } }); @@ -758,6 +775,10 @@ } buffer.push(text); }, + ignore: function(text) { + // `text` === strings that start with `` or `%>`. + buffer.push(options.removeIgnored ? '' : trimWhitespace(text)); // `text` allowed by default. + }, doctype: function(doctype) { buffer.push(options.useShortDoctype ? '' : collapseWhitespace(doctype)); } diff --git a/index.html b/index.html index b51d2fb..5555826 100644 --- a/index.html +++ b/index.html @@ -108,6 +108,19 @@ +
  • + + +