From: Juriy Zaytsev Date: Mon, 8 Mar 2010 06:06:23 +0000 (-0500) Subject: Fix a bug with space-less attributes. Move scripts to the bottom. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=7703e9ca121a6c28dd2400f525a5d2dd0e2f5f80;p=html-minifier.git Fix a bug with space-less attributes. Move scripts to the bottom. --- diff --git a/index.html b/index.html index d1ef19a..76f8fe8 100644 --- a/index.html +++ b/index.html @@ -4,11 +4,6 @@ HTML minifier - - - - - @@ -161,6 +156,9 @@ Source and bugtracker are hosted on Github.

+ + + \ No newline at end of file diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 0ac01c5..35cfe61 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -107,6 +107,10 @@ return text.replace(/^\s*\s*$/, ''); } + function isOptionalTag(tag) { + return (/^(?:html|t?body|t?head|tfoot|tr)$/).test(tag); + } + var reEmptyAttribute = new RegExp( '^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(' + '?:down|up|over|move|out)|key(?:press|down|up)))$'); @@ -125,10 +129,6 @@ return tag !== 'textarea'; } - function isOptionalTag(tag) { - return (/^(?:html|t?body|t?head|tfoot|tr)$/).test(tag); - } - function canCollapseWhitespace(tag) { return !(/^(?:script|style|pre|textarea)$/.test(tag)); } @@ -185,7 +185,6 @@ HTMLParser(value, { start: function( tag, attrs, unary ) { - tag = tag.toLowerCase(); currentTag = tag; currentChars = ''; @@ -200,6 +199,7 @@ buffer.push('>'); }, end: function( tag ) { + var isElementEmpty = currentChars === '' && tag === currentTag; if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag))) { // remove last "element" from buffer, return diff --git a/src/htmlparser.js b/src/htmlparser.js index 31dcfd0..e6fbcf4 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -27,7 +27,7 @@ (function(){ // Regular Expressions for parsing tags and attributes - var startTag = /^<(\w+)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/, + var startTag = /^<(\w+)((?:\s*[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/, endTag = /^<\/(\w+)[^>]*>/, attr = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g, doctype = /^]+>/i; @@ -166,7 +166,6 @@ arguments[3] ? arguments[3] : arguments[4] ? arguments[4] : fillAttrs[name] ? name : ""; - attrs.push({ name: name, value: value, diff --git a/tests/index.html b/tests/index.html index c7f12c4..73ab051 100644 --- a/tests/index.html +++ b/tests/index.html @@ -38,6 +38,10 @@ equals(minify('