From: Hugo Wetterberg Date: Fri, 5 Aug 2011 13:48:20 +0000 (+0200) Subject: Modified to work with node and potentially npm. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=cf25eaa25f8307a129625136d95879c41d76cd20;p=html-minifier.git Modified to work with node and potentially npm. --- diff --git a/package.json b/package.json new file mode 100644 index 0000000..2da4449 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "html-minifier", + "version": "0.43", + "description": "HTMLMinifier is a Javascript-based HTML minifier with lint-like capabilities.", + "keywords": ["html", "minifier", "lint"], + "maintainers": [{ + "name": "Juriy Zaytsev", + "email": "kangax@gmail.com", + "web": "http://perfectionkills.com" + }], + "contributors": [{ + "name": "Gilmore Davidson", + "web": "https://github.com/gilmoreorless" + }, + { + "name": "Hugo Wetterberg", + "email": "hugo@wetterberg.nu" + }], + "licenses": [{ + "type": "MIT", + "url": "https://github.com/hugowetterberg/html-minifier/blob/gh-pages/src/license.txt" + }], + "repositories": [{ + "type": "git", + "url": "git://github.com/hugowetterberg/html-minifier.git" + }], + "engines": { + "node": ">=0.4.8" + }, + "directories": { + "src": "./src" + }, + "main": "./src/htmlminifier.js" +} + diff --git a/src/htmllint.js b/src/htmllint.js index c97dfb7..f61d579 100644 --- a/src/htmllint.js +++ b/src/htmllint.js @@ -147,4 +147,4 @@ global.HTMLLint = Lint; -})(this); \ No newline at end of file +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/src/htmlminifier.js b/src/htmlminifier.js index b6d63b6..ab0cb08 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -9,7 +9,7 @@ (function(global){ - var log; + var log, HTMLParser; if (global.console && global.console.log) { log = function(message) { // "preserving" `this` @@ -20,6 +20,13 @@ log = function(){ }; } + if (global.HTMLParser) { + HTMLParser = global.HTMLParser; + } + else if (typeof require === 'function') { + HTMLParser = require('./htmlparser').HTMLParser; + } + function trimWhitespace(str) { return str.replace(/^\s+/, '').replace(/\s+$/, ''); } @@ -367,4 +374,4 @@ // export global.minify = minify; -})(this); \ No newline at end of file +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file diff --git a/src/htmlparser.js b/src/htmlparser.js index e6fbcf4..50ccbcb 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -24,7 +24,7 @@ * */ -(function(){ +(function(global){ // Regular Expressions for parsing tags and attributes var startTag = /^<(\w+)((?:\s*[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/, @@ -53,7 +53,7 @@ var reCache = { }, stackedTag, re; - var HTMLParser = this.HTMLParser = function( html, handler ) { + var HTMLParser = global.HTMLParser = function( html, handler ) { var index, chars, match, stack = [], last = html; stack.last = function(){ return this[ this.length - 1 ]; @@ -201,7 +201,7 @@ } }; - this.HTMLtoXML = function( html ) { + global.HTMLtoXML = function( html ) { var results = ""; HTMLParser(html, { @@ -227,7 +227,7 @@ return results; }; - this.HTMLtoDOM = function( html, doc ) { + global.HTMLtoDOM = function( html, doc ) { // There can be only one of these elements var one = makeMap("html,head,body,title"); @@ -324,4 +324,4 @@ } return obj; } -})(); \ No newline at end of file +})(typeof exports === 'undefined' ? window : exports); \ No newline at end of file