From: kangax Date: Wed, 22 Jan 2014 18:19:40 +0000 (-0500) Subject: Add minify script X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2c1e94caef30e08418b584c455b96c279bcc96eb;p=html-minifier.git Add minify script --- diff --git a/dist/all.min.js b/dist/all.min.js new file mode 100644 index 0000000..c804f82 --- /dev/null +++ b/dist/all.min.js @@ -0,0 +1,25 @@ +/* + * HTML Parser By John Resig (ejohn.org) + * Modified by Juriy "kangax" Zaytsev + * Original code by Erik Arvidsson, Mozilla Public License + * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js + * + * // Use like so: + * HTMLParser(htmlString, { + * start: function(tag, attrs, unary) {}, + * end: function(tag) {}, + * chars: function(text) {}, + * comment: function(text) {} + * }); + * + * // or to get an XML string: + * HTMLtoXML(htmlString); + * + * // or to get an XML DOM Document + * HTMLtoDOM(htmlString); + * + * // or to inject into an existing document/DOM node + * HTMLtoDOM(htmlString, document); + * HTMLtoDOM(htmlString, document.body); + * + */(function(e){function m(e){var t={},n=e.split(",");for(var r=0;r\s]+))?)*)\s*(\/?)>/,n=/^<\/([\w:-]+)[^>]*>/,r=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g,i=/^]+>/i,s=/<(%|\?)/;endIgnore=/(%|\?)>/;var o=m("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"),u=m("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"),a=m("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"),f=m("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),l=m("script,style"),c={},h,p,d,v=e.HTMLParser=function(e,v){function T(e,t,n,i){while(!v.html5&&b.last()&&u[b.last()])N("",b.last());a[t]&&b.last()===t&&N("",t),i=o[t]||!!i,i||b.push(t);if(v.start){var s=[];n.replace(r,function(e,t){var n=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:f[t]?t:"";s.push({name:t,value:n,escaped:n.replace(/(^|[^\\])"/g,'$1\\"')})}),v.start&&v.start(t,s,i)}}function N(e,t){var n;if(!t)n=0;else for(n=b.length-1;n>=0;n--)if(b[n]===t)break;if(n>=0){for(var r=b.length-1;r>=n;r--)v.end&&v.end(b[r]);b.length=n}}var m,g,y,b=[],w=e,E,S;b.last=function(){return this[this.length-1]};while(e){g=!0;if(!b.last()||!l[b.last()]){e.indexOf(""),m>=0&&(v.comment&&v.comment(e.substring(4,m)),e=e.substring(m+3),g=!1)):e.search(s)===0?(m=e.search(endIgnore),m>=0&&(v.ignore&&v.ignore(e.substring(0,m+2)),e=e.substring(m+2),g=!1)):(y=i.exec(e))?(v.doctype&&v.doctype(y[0]),e=e.substring(y[0].length),g=!1):e.indexOf("]*>","i")),e=e.replace(p,function(e,t){return h!=="script"&&h!=="style"&&(t=t.replace(//g,"$1").replace(//g,"$1")),v.chars&&v.chars(t),""}),N("",h);if(e===w)throw"Parse Error: "+e;w=e}N()};e.HTMLtoXML=function(e){var t="";return v(e,{start:function(e,n,r){t+="<"+e;for(var i=0;i"},end:function(e){t+=""},chars:function(e){t+=e},comment:function(e){t+=""},ignore:function(e){t+=e}}),t},e.HTMLtoDOM=function(e,t){var n=m("html,head,body,title"),r={link:"head",base:"head"};t?t=t.ownerDocument||t.getOwnerDocument&&t.getOwnerDocument()||t:typeof DOMDocument!="undefined"?t=new DOMDocument:typeof document!="undefined"&&document.implementation&&document.implementation.createDocument?t=document.implementation.createDocument("","",null):typeof ActiveX!="undefined"&&(t=new ActiveXObject("Msxml.DOMDocument"));var i=[],s=t.documentElement||t.getDocumentElement&&t.getDocumentElement();!s&&t.createElement&&function(){var e=t.createElement("html"),n=t.createElement("head");n.appendChild(t.createElement("title")),e.appendChild(n),e.appendChild(t.createElement("body")),t.appendChild(e)}();if(t.getElementsByTagName)for(var o in n)n[o]=t.getElementsByTagName(o)[0];var u=n.body;return v(e,{start:function(e,s,o){if(n[e]){u=n[e];return}var a=t.createElement(e);for(var f in s)a.setAttribute(s[f].name,s[f].value);r[e]&&typeof n[r[e]]!="boolean"?n[r[e]].appendChild(a):u&&u.appendChild&&u.appendChild(a),o||(i.push(a),u=a)},end:function(){i.length-=1,u=i[i.length-1]},chars:function(e){u.appendChild(t.createTextNode(e))},comment:function(){},ignore:function(){}}),t}})(typeof exports=="undefined"?this:exports),function(e){function i(e){return e.replace(/\s+/g," ")}function s(e,t,n){var r=["a","abbr","acronym","b","bdi","bdo","big","button","cite","code","del","dfn","em","font","i","ins","kbd","mark","q","rt","rp","s","samp","small","span","strike","strong","sub","sup","time","tt","u","var"];return t&&t!=="img"&&(t.substr(0,1)!=="/"||t.substr(0,1)==="/"&&r.indexOf(t.substr(1))===-1)&&(e=e.replace(/^\s+/,"")),n&&n!=="img"&&(n.substr(0,1)==="/"||n.substr(0,1)!=="/"&&r.indexOf(n)===-1)&&(e=e.replace(/\s+$/,"")),t&&n?e.replace(/[\t\n\r]+/g," ").replace(/[ ]+/g," "):e}function o(e){return/\[if[^\]]+\]/.test(e)||/\s*(]+$/.test(e)&&!/\/$/.test(e)&&!/\/$/.test(e)}function l(e,t){for(var n=e.length;n--;)if(e[n].name.toLowerCase()===t)return!0;return!1}function c(e,t,n,i){return n=r(n.toLowerCase()),e==="script"&&t==="language"&&n==="javascript"||e==="form"&&t==="method"&&n==="get"||e==="input"&&t==="type"&&n==="text"||e==="script"&&t==="charset"&&!l(i,"src")||e==="a"&&t==="name"&&l(i,"id")||e==="area"&&t==="shape"&&n==="rect"}function h(e,t,n){return e==="script"&&t==="type"&&r(n.toLowerCase())==="text/javascript"}function p(e,t,n){return(e==="style"||e==="link")&&t==="type"&&r(n.toLowerCase())==="text/css"}function d(e){return/^(?:allowfullscreen|async|autofocus|checked|compact|declare|default|defer|disabled|formnovalidate|hidden|inert|ismap|itemscope|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|readonly|required|reversed|seamless|selected|sortable|truespeed|typemustmatch)$/.test(e)}function v(e,t){return/^(?:a|area|link|base)$/.test(t)&&e==="href"||t==="img"&&/^(?:src|longdesc|usemap)$/.test(e)||t==="object"&&/^(?:classid|codebase|data|usemap)$/.test(e)||t==="q"&&e==="cite"||t==="blockquote"&&e==="cite"||(t==="ins"||t==="del")&&e==="cite"||t==="form"&&e==="action"||t==="input"&&(e==="src"||e==="usemap")||t==="head"&&e==="profile"||t==="script"&&(e==="src"||e==="for")}function m(e,t){return/^(?:a|area|object|button)$/.test(t)&&e==="tabindex"||t==="input"&&(e==="maxlength"||e==="tabindex")||t==="select"&&(e==="size"||e==="tabindex")||t==="textarea"&&/^(?:rows|cols|tabindex)$/.test(e)||t==="colgroup"&&e==="span"||t==="col"&&e==="span"||(t==="th"||t==="td")&&(e==="rowspan"||e==="colspan")}function g(e,t,n){return a(t)?r(n).replace(/^javascript:\s*/i,"").replace(/\s*;$/,""):t==="class"?i(r(n)):v(t,e)||m(t,e)?r(n):t==="style"?r(n).replace(/\s*;\s*$/,""):n}function y(e){return e.replace(/^(\[[^\]]+\]>)\s*/,"$1").replace(/\s*(\s*\*\/|\/\/\s*\]\]>)\s*$/,"")}function S(e,t){return e.replace(w[t],"").replace(E[t],"")}function x(e){return/^(?:html|t?body|t?head|tfoot|tr|option)$/.test(e)}function N(e,t,n){var r=/^(["'])?\s*\1$/.test(n);return r?e==="input"&&t==="value"||T.test(t):!1}function C(e){return e!=="textarea"}function k(e){return!/^(?:script|style|pre|textarea)$/.test(e)}function L(e){return!/^(?:pre|textarea)$/.test(e)}function A(e,t,n,r){var i=e.name.toLowerCase(),s=e.escaped,o;if(r.removeRedundantAttributes&&c(n,i,s,t)||r.removeScriptTypeAttributes&&h(n,i,s)||r.removeStyleLinkTypeAttributes&&p(n,i,s))return"";s=g(n,i,s);if(!r.removeAttributeQuotes||!f(s))s='"'+s+'"';return r.removeEmptyAttributes&&N(n,i,s)?"":(r.collapseBooleanAttributes&&d(i)?o=i:o=i+"="+s," "+o)}function O(e){var t=["canCollapseWhitespace","canTrimWhitespace"];for(var n=0,r=t.length;n")},end:function(e){a.collapseWhitespace&&(d.length&&e===d[d.length-1]&&d.pop(),v.length&&e===v[v.length-1]&&v.pop());var t=c===""&&e===h;if(a.removeEmptyElements&&t&&C(e)){l.splice(l.lastIndexOf("<"));return}if(a.removeOptionalTags&&x(e))return;l.push(""),f.push.apply(f,l),l.length=0,c=""},chars:function(e,t,n){if(h==="script"||h==="style")a.removeCommentsFromCDATA&&(e=S(e,h)),a.removeCDATASectionsFromCDATA&&(e=b(e));a.collapseWhitespace&&(d.length||(e=t||n?s(e,t,n):r(e)),v.length||(e=i(e))),c=e,m&&m.testChars(e),l.push(e)},comment:function(e){a.removeComments?o(e)?e="":u(e)?e="":e="":e="",l.push(e)},ignore:function(e){l.push(a.removeIgnored?"":e)},doctype:function(e){l.push(a.useShortDoctype?"":i(e))}}),f.push.apply(f,l);var T=f.join("");return t("minified in: "+(new Date-g)+"ms"),T}var t,n;e.console&&e.console.log?t=function(t){e.console.log(t)}:t=function(){},e.HTMLParser?n=e.HTMLParser:typeof require=="function"&&(n=require("./htmlparser").HTMLParser);var r=function(e){return e.replace(/^\s+/,"").replace(/\s+$/,"")};String.prototype.trim&&(r=function(e){return e.trim()});var w={script:/^\s*(?:\/\/)?\s*\s*$/,style:/\s*-->\s*$/},T=new RegExp("^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(?:down|up|over|move|out)|key(?:press|down|up)))$");typeof exports!="undefined"?exports.minify=M:e.minify=M}(this),function(e){function t(e){return/^(?:b|i|big|small|hr|blink|marquee)$/.test(e)}function n(e){return/^(?:applet|basefont|center|dir|font|isindex|s|strike|u)$/.test(e)}function r(e){return/^on[a-z]+/.test(e)}function i(e){return"style"===e.toLowerCase()}function s(e,t){return t==="align"&&/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(e)||t==="alink"&&e==="body"||t==="alt"&&e==="applet"||t==="archive"&&e==="applet"||t==="background"&&e==="body"||t==="bgcolor"&&/^(?:table|t[rdh]|body)$/.test(e)||t==="border"&&/^(?:img|object)$/.test(e)||t==="clear"&&e==="br"||t==="code"&&e==="applet"||t==="codebase"&&e==="applet"||t==="color"&&/^(?:base(?:font)?)$/.test(e)||t==="compact"&&/^(?:dir|[dou]l|menu)$/.test(e)||t==="face"&&/^base(?:font)?$/.test(e)||t==="height"&&/^(?:t[dh]|applet)$/.test(e)||t==="hspace"&&/^(?:applet|img|object)$/.test(e)||t==="language"&&e==="script"||t==="link"&&e==="body"||t==="name"&&e==="applet"||t==="noshade"&&e==="hr"||t==="nowrap"&&/^t[dh]$/.test(e)||t==="object"&&e==="applet"||t==="prompt"&&e==="isindex"||t==="size"&&/^(?:hr|font|basefont)$/.test(e)||t==="start"&&e==="ol"||t==="text"&&e==="body"||t==="type"&&/^(?:li|ol|ul)$/.test(e)||t==="value"&&e==="li"||t==="version"&&e==="html"||t==="vlink"&&e==="body"||t==="vspace"&&/^(?:applet|img|object)$/.test(e)||t==="width"&&/^(?:hr|td|th|applet|pre)$/.test(e)}function o(e,t){return e==="href"&&/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(t)}function u(){this.log=[],this._lastElement=null,this._isElementRepeated=!1}u.prototype.testElement=function(e){n(e)?this.log.push('
  • Found deprecated <'+e+"> element
  • "):t(e)?this.log.push('
  • Found presentational <'+e+"> element
  • "):this.checkRepeatingElement(e)},u.prototype.checkRepeatingElement=function(e){e==="br"&&this._lastElement==="br"?this._isElementRepeated=!0:this._isElementRepeated&&(this._reportRepeatingElement(),this._isElementRepeated=!1),this._lastElement=e},u.prototype._reportRepeatingElement=function(){this.log.push("
  • Found <br> sequence. Try replacing it with styling.
  • ")},u.prototype.testAttribute=function(e,t,n){r(t)?this.log.push('
  • Found event attribute (',t,") on <"+e+"> element
  • "):s(e,t)?this.log.push('
  • Found deprecated '+t+" attribute on <",e,"> element
  • "):i(t)?this.log.push('
  • Found style attribute on <',e,"> element
  • "):o(t,n)&&this.log.push('
  • Found inaccessible attribute (on <',e,"> element)
  • ")},u.prototype.testChars=function(e){this._lastElement="",/( \s*){2,}/.test(e)&&this.log.push("
  • Found repeating &nbsp; sequence. Try replacing it with styling.
  • ")},u.prototype.test=function(e,t,n){this.testElement(e),this.testAttribute(e,t,n)},u.prototype.populate=function(e){this._isElementRepeated&&this._reportRepeatingElement();var t;this.log.length&&e&&(t="
      "+this.log.join("")+"
    ",e.innerHTML=t)},e.HTMLLint=u}(typeof exports=="undefined"?this:exports); \ No newline at end of file diff --git a/package.json b/package.json index 32e046b..461944c 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,9 @@ "scripts": { "test": "npm run-script lint && npm run-script build && node test.js", "build": "cat src/htmlparser.js src/htmlminifier.js src/htmllint.js > dist/all.js", - "lint": "jshint src/htmlminifier.js src/htmllint.js" + "minify": "uglifyjs --output dist/all.min.js dist/all.js", + "lint": "jshint src/htmlminifier.js src/htmllint.js", + "dist": "npm run-script build && npm run-script minify" }, "devDependencies": { "qunit": "0.5.x",