From: Juriy Zaytsev Date: Mon, 22 Mar 2010 03:16:44 +0000 (-0400) Subject: Make lint report repeating
elements and " " sequences. Rephrase report... X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8c739357e90ebeb9e4b227605448dc939fe580b2;p=html-minifier.git Make lint report repeating
elements and " " sequences. Rephrase report messages and number them. Bump version to 0.42. --- diff --git a/index.html b/index.html index 5668fdb..a933add 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@
-

HTML Minifier (ver. 0.41)

+

HTML Minifier (ver. 0.42)

Minifier is very draft and is not yet thoroughly tested. Use at your own risk.

@@ -165,7 +165,6 @@
  • HTMLLint: warn about repeating attributes (e.g. multiple styles, classes, etc.)
  • -
  • HTMLLint: warn about repeating &nbsp; or <br> sequences
  • HTMLLint: warn about missing doctype
diff --git a/src/htmllint.js b/src/htmllint.js index 53b6dea..c97dfb7 100644 --- a/src/htmllint.js +++ b/src/htmllint.js @@ -65,40 +65,67 @@ function Lint() { this.log = [ ]; + this._lastElement = null; + this._isElementRepeated = false; } Lint.prototype.testElement = function(tag) { if (isDeprecatedElement(tag)) { this.log.push( - '
  • Warning: found deprecated element (', - tag, ')
  • '); + '
  • Found deprecated <' + + tag + '> element
  • '); } else if (isPresentationalElement(tag)) { this.log.push( - '
  • Warning: found presentational element (', - tag, ')
  • '); + '
  • Found presentational <' + + tag + '> element
  • '); } + else { + this.checkRepeatingElement(tag); + } + }; + + Lint.prototype.checkRepeatingElement = function(tag) { + if (tag === 'br' && this._lastElement === 'br') { + this._isElementRepeated = true; + } + else if (this._isElementRepeated) { + this._reportRepeatingElement(); + this._isElementRepeated = false; + } + this._lastElement = tag; + }; + + Lint.prototype._reportRepeatingElement = function() { + this.log.push('
  • Found <br> sequence. Try replacing it with styling.
  • '); }; Lint.prototype.testAttribute = function(tag, attrName, attrValue) { if (isEventAttribute(attrName)) { this.log.push( - '
  • Warning: found event attribute (', - attrName, ')
  • '); + '
  • Found event attribute (', + attrName, ') on <' + tag + '> element
  • '); } else if (isDeprecatedAttribute(tag, attrName)) { this.log.push( - '
  • Warning: found deprecated attribute (', - attrName, ' on <', tag, '> element)
  • '); + '
  • Found deprecated ' + + attrName + ' attribute on <', tag, '> element
  • '); } else if (isStyleAttribute(attrName)) { this.log.push( - '
  • Warning: found style attribute (on <', tag, '> element)
  • '); + '
  • Found style attribute on <', tag, '> element
  • '); } else if (isInaccessibleAttribute(attrName, attrValue)) { this.log.push( - '
  • Warning: found inaccessible attribute '+ - '(on <', tag, '> element)
  • '); + '
  • Found inaccessible attribute '+ + '(on <', tag, '> element)
  • '); + } + }; + + Lint.prototype.testChars = function(chars) { + this._lastElement = ''; + if (/( \s*){2,}/.test(chars)) { + this.log.push('
  • Found repeating &nbsp; sequence. Try replacing it with styling.
  • '); } }; @@ -108,9 +135,12 @@ }; Lint.prototype.populate = function(writeToElement) { + if (this._isElementRepeated) { + this._reportRepeatingElement(); + } var report; if (this.log.length && writeToElement) { - report = '
      ' + this.log.join('') + '
    '; + report = '
      ' + this.log.join('') + '
    '; writeToElement.innerHTML = report; } }; diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 867457e..22308dc 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1,5 +1,5 @@ /*! - * HTMLMinifier v0.41 + * HTMLMinifier v0.42 * http://kangax.github.com/html-minifier/ * * Copyright (c) 2010 Juriy "kangax" Zaytsev @@ -301,6 +301,7 @@ } } currentChars = text; + lint && lint.testChars(text); buffer.push(text); }, comment: function( text ) {