From fddd3b47046c2ac0805f1398b5bcc0a37929913f Mon Sep 17 00:00:00 2001 From: Steven Vachon Date: Tue, 5 Aug 2014 15:04:55 -0400 Subject: [PATCH] minify urls --- README.md | 1 + assets/master.js | 1 + assets/relateurl-browser.js | 1 + cli.js | 1 + dist/htmlminifier.js | 40 ++++++++++++++++++++++++++++++++++++- dist/htmlminifier.min.js | 2 +- index.html | 17 ++++++++++++++++ package.json | 3 ++- src/htmlminifier.js | 40 ++++++++++++++++++++++++++++++++++++- tests/index.html | 1 + tests/minifier.js | 7 +++++++ 11 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 assets/relateurl-browser.js diff --git a/README.md b/README.md index f05bd13..ed40cf1 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ How does HTMLMinifier compare to [another solution](http://www.willpeavy.com/min | `caseSensitive` | Treat attributes in case sensitive manner (useful for SVG; e.g. viewBox) | `false` | | `minifyJS` | Minify Javascript in script elements and on* attributes (uses [UglifyJS](https://github.com/mishoo/UglifyJS2)) | `false` (could be `true`, `false`, `Object` (options)) | | `minifyCSS` | Minify CSS in style elements and style attributes (uses [clean-css](https://github.com/GoalSmashers/clean-css)) | `false` (could be `true`, `false`, `Object` (options)) | +| `minifyURLs` | Minify URLs in various attributes (uses [relateurl](https://github.com/stevenvachon/relateurl)) | `false` (could be `Object` (options)) | | `ignoreCustomComments` | Array of regex'es that allow to ignore certain comments, when matched | `[ ]` | | `processScripts` | Array of strings corresponding to types of script elements to process through minifier (e.g. `text/ng-template`, `text/x-handlebars-template`, etc.) | `[ ]` | | `maxLineLength` | Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points. | diff --git a/assets/master.js b/assets/master.js index 48c2f3b..4144f8b 100644 --- a/assets/master.js +++ b/assets/master.js @@ -32,6 +32,7 @@ minifyJS: byId('minify-js').checked, processScripts: byId('minify-js-templates').checked ? byId('minify-js-templates-type').value : false, minifyCSS: byId('minify-css').checked, + minifyURLs: byId('minify-urls').checked ? { site:byId('minify-urls-siteurl').value } : false, lint: byId('use-htmllint').checked ? new HTMLLint() : null, maxLineLength: parseInt(byId('max-line-length').value, 10) }; diff --git a/assets/relateurl-browser.js b/assets/relateurl-browser.js new file mode 100644 index 0000000..083f828 --- /dev/null +++ b/assets/relateurl-browser.js @@ -0,0 +1 @@ +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.RelateUrl=t()}}(function(){var t;return function e(t,r,n){function o(s,i){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!i&&u)return u(s,!0);if(a)return a(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var l=r[s]={exports:{}};t[s][0].call(l.exports,function(e){var r=t[s][1][e];return o(r?r:e)},l,l.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s-1){if(++a-1&&(null==t.port&&(t.port=r),t.extra.portIsDefault=t.port==r)}e.exports=r},{}],9:[function(t,e){"use strict";function r(t,e){t.query.string.full=n(t.query.object,!1),e.removeEmptyQueries&&(t.query.string.stripped=n(t.query.object,!0))}function n(t,e){var r=0,n="";for(var o in t)if(""!=o&&t.hasOwnProperty(o)){var a=t[o];""==a&&e||(n+=1==++r?"?":"&",o=encodeURIComponent(o),n+=""!=a?o+"="+encodeURIComponent(a).replace(/%20/g,"+"):o)}return n}e.exports=r},{}],10:[function(t,e){"use strict";function r(t){var e=t.protocol;return e&&e.indexOf(":")==e.length-1&&(e=e.substr(0,e.length-1)),t.host={full:t.hostname,stripped:null},t.path={absolute:{array:null,string:t.pathname},relative:{array:null,string:null}},t.query={object:t.query,string:{full:null,stripped:null}},t.extra={hrefInfo:{minimumPathOnly:null,minimumResourceOnly:null,minimumQueryOnly:null,minimumHashOnly:null,empty:null,separatorOnlyQuery:"?"==t.search},portIsDefault:null,relation:{maximumScheme:null,maximumAuth:null,maximumHost:null,maximumPort:null,maximumPath:null,maximumResource:null,maximumQuery:null,maximumHash:null,minimumScheme:null,minimumAuth:null,minimumHost:null,minimumPort:null,minimumPath:null,minimumResource:null,minimumQuery:null,minimumHash:null,overridesQuery:null},resourceIsIndex:null,slashes:t.slashes},t.resource=null,t.scheme=e,delete t.hostname,delete t.pathname,delete t.protocol,delete t.search,delete t.slashes,t}function n(t,e){var r=!0;return e.rejectedSchemes.every(function(e){return r=!(0==t.indexOf(e+":"))}),r}function o(t,e){return n(t,e)?r(a(t,!0,e.slashesDenoteHost)):{href:t,valid:!1}}var a=t("url").parse;e.exports=o},{url:22}],11:[function(t,e){"use strict";function r(t,e,r){s.upToPath(t,e,r),t.extra.relation.minimumScheme&&(t.scheme=e.scheme),t.extra.relation.minimumAuth&&(t.auth=e.auth),t.extra.relation.minimumHost&&(t.host=i.clone(e.host)),t.extra.relation.minimumPort&&o(t,e),t.extra.relation.minimumScheme&&n(t,e),s.pathOn(t,e,r),t.extra.relation.minimumResource&&a(t,e),t.extra.relation.minimumQuery&&(t.query=i.clone(e.query)),t.extra.relation.minimumHash&&(t.hash=e.hash)}function n(t,e){if(t.extra.relation.maximumHost||!t.extra.hrefInfo.minimumResourceOnly){var r=t.path.absolute.array,n="/";r?(t.extra.hrefInfo.minimumPathOnly&&0!=t.path.absolute.string.indexOf("/")&&(r=e.path.absolute.array.concat(r)),r=u.resolveDotSegments(r),n+=u.join(r)):r=[],t.path.absolute.array=r,t.path.absolute.string=n}else t.path=i.clone(e.path)}function o(t,e){t.port=e.port,t.extra.portIsDefault=e.extra.portIsDefault}function a(t,e){t.resource=e.resource,t.extra.resourceIsIndex=e.extra.resourceIsIndex}var s=t("./findRelation"),i=t("../util/object"),u=t("../util/path");e.exports=r},{"../util/object":15,"../util/path":16,"./findRelation":12}],12:[function(t,e){"use strict";function r(t,e,r){var n=t.extra.hrefInfo.minimumPathOnly,o=t.scheme==e.scheme||!t.scheme,a=o&&(t.auth==e.auth||r.removeAuth||n),s=r.ignore_www?"stripped":"full",i=a&&(t.host[s]==e.host[s]||n),u=i&&(t.port==e.port||n);t.extra.relation.minimumScheme=o,t.extra.relation.minimumAuth=a,t.extra.relation.minimumHost=i,t.extra.relation.minimumPort=u,t.extra.relation.maximumScheme=!o||o&&!a,t.extra.relation.maximumAuth=!o||o&&!i,t.extra.relation.maximumHost=!o||o&&!u}function n(t,e,r){var n=t.extra.hrefInfo.minimumQueryOnly,o=t.extra.hrefInfo.minimumHashOnly,a=t.extra.hrefInfo.empty,s=t.extra.relation.minimumPort,i=t.extra.relation.minimumScheme,u=s&&t.path.absolute.string==e.path.absolute.string,h=t.resource==e.resource||!t.resource&&e.extra.resourceIsIndex||r.removeDirectoryIndexes&&t.extra.resourceIsIndex&&!e.resource,l=u&&(h||n||o||a),c=r.removeEmptyQueries?"stripped":"full",f=t.query.string[c],m=e.query.string[c],p=l&&!!f&&f==m||(o||a)&&!t.extra.hrefInfo.separatorOnlyQuery,v=p&&t.hash==e.hash;t.extra.relation.minimumPath=u,t.extra.relation.minimumResource=l,t.extra.relation.minimumQuery=p,t.extra.relation.minimumHash=v,t.extra.relation.maximumPort=!i||i&&!u,t.extra.relation.maximumPath=!i||i&&!l,t.extra.relation.maximumResource=!i||i&&!p,t.extra.relation.maximumQuery=!i||i&&!v,t.extra.relation.maximumHash=!i||i&&!v,t.extra.relation.overridesQuery=u&&t.extra.relation.maximumResource&&!p&&!!m}e.exports={pathOn:n,upToPath:r}},{}],13:[function(t,e){"use strict";function r(t,e,r){return n(e,t,r),o(e,t,r),e}var n=t("./absolutize"),o=t("./relativize");e.exports=r},{"./absolutize":11,"./relativize":14}],14:[function(t,e){"use strict";function r(t,e){var r=[],n=!0,o=-1;return e.forEach(function(e,a){n&&(t[a]!=e?n=!1:o=a),n||r.push("..")}),t.forEach(function(t,e){e>o&&r.push(t)}),r}function n(t,e){if(t.extra.relation.minimumScheme){var n=r(t.path.absolute.array,e.path.absolute.array);t.path.relative.array=n,t.path.relative.string=o.join(n)}}var o=t("../util/path");e.exports=n},{"../util/path":16}],15:[function(t,e){"use strict";function r(t){if(t instanceof Object){var e=t instanceof Array?[]:{};for(var n in t)t.hasOwnProperty(n)&&(e[n]=r(t[n]));return e}return t}function n(t){return t instanceof Object&&!(t instanceof Array)}function o(t,e){if(t instanceof Object&&e instanceof Object)for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}e.exports={clone:r,isObject:n,shallowMerge:o}},{}],16:[function(t,e){"use strict";function r(t){return t.length?t.join("/")+"/":""}function n(t){var e=[];return t.forEach(function(t){".."!=t?"."!=t&&e.push(t):e.length&&e.splice(e.length-1,1)}),e}e.exports={join:r,resolveDotSegments:n}},{}],17:[function(t,e){"use strict";function r(t,e){this.options=a(e,{defaultPorts:{ftp:21,http:80,https:443},directoryIndexes:["index.html"],ignore_www:!1,output:r.SHORTEST,rejectedSchemes:["data","javascript","mailto"],removeAuth:!1,removeDirectoryIndexes:!0,removeEmptyQueries:!1,schemeRelative:!0,site:void 0,slashesDenoteHost:!0}),this.from=i.from(t,this.options,null)}var n=t("./constants"),o=t("./format"),a=t("./options"),s=t("./util/object"),i=t("./parse"),u=t("./relate");r.prototype.relate=function(t,e,r){if(s.isObject(e)?(r=e,e=t,t=null):e||(e=t,t=null),r=a(r,this.options),t=t||r.site,t=i.from(t,r,this.from),!t||!t.href)throw new Error("from value not defined.");if(t.extra.hrefInfo.minimumPathOnly)throw new Error("from value supplied is not absolute: "+t.href);return e=i.to(e,r),e.valid===!1?e.href:(e=u(t,e,r),e=o(e,r))},r.relate=function(t,e,n){return(new r).relate(t,e,n)};for(var h in n)n.hasOwnProperty(h)&&Object.defineProperty(r,h,{value:n[h]});e.exports=r},{"./constants":1,"./format":2,"./options":3,"./parse":6,"./relate":13,"./util/object":15}],18:[function(e,r,n){(function(e){!function(o){function a(t){throw RangeError(U[t])}function s(t,e){for(var r=t.length;r--;)t[r]=e(t[r]);return t}function i(t,e){return s(t.split(C),e).join(".")}function u(t){for(var e,r,n=[],o=0,a=t.length;a>o;)e=t.charCodeAt(o++),e>=55296&&56319>=e&&a>o?(r=t.charCodeAt(o++),56320==(64512&r)?n.push(((1023&e)<<10)+(1023&r)+65536):(n.push(e),o--)):n.push(e);return n}function h(t){return s(t,function(t){var e="";return t>65535&&(t-=65536,e+=D(t>>>10&1023|55296),t=56320|1023&t),e+=D(t)}).join("")}function l(t){return 10>t-48?t-22:26>t-65?t-65:26>t-97?t-97:j}function c(t,e){return t+22+75*(26>t)-((0!=e)<<5)}function f(t,e,r){var n=0;for(t=r?Q(t/E):t>>1,t+=Q(t/e);t>L*A>>1;n+=j)t=Q(t/L);return Q(n+(L+1)*t/(t+R))}function m(t){var e,r,n,o,s,i,u,c,m,p,v=[],y=t.length,x=0,d=P,g=q;for(r=t.lastIndexOf(S),0>r&&(r=0),n=0;r>n;++n)t.charCodeAt(n)>=128&&a("not-basic"),v.push(t.charCodeAt(n));for(o=r>0?r+1:0;y>o;){for(s=x,i=1,u=j;o>=y&&a("invalid-input"),c=l(t.charCodeAt(o++)),(c>=j||c>Q((I-x)/i))&&a("overflow"),x+=c*i,m=g>=u?w:u>=g+A?A:u-g,!(m>c);u+=j)p=j-m,i>Q(I/p)&&a("overflow"),i*=p;e=v.length+1,g=f(x-s,e,0==s),Q(x/e)>I-d&&a("overflow"),d+=Q(x/e),x%=e,v.splice(x++,0,d)}return h(v)}function p(t){var e,r,n,o,s,i,h,l,m,p,v,y,x,d,g,b=[];for(t=u(t),y=t.length,e=P,r=0,s=q,i=0;y>i;++i)v=t[i],128>v&&b.push(D(v));for(n=o=b.length,o&&b.push(S);y>n;){for(h=I,i=0;y>i;++i)v=t[i],v>=e&&h>v&&(h=v);for(x=n+1,h-e>Q((I-r)/x)&&a("overflow"),r+=(h-e)*x,e=h,i=0;y>i;++i)if(v=t[i],e>v&&++r>I&&a("overflow"),v==e){for(l=r,m=j;p=s>=m?w:m>=s+A?A:m-s,!(p>l);m+=j)g=l-p,d=j-p,b.push(D(c(p+g%d,0))),l=Q(g/d);b.push(D(c(l,0))),s=f(r,x,n==o),r=0,++n}++r,++e}return b.join("")}function v(t){return i(t,function(t){return T.test(t)?m(t.slice(4).toLowerCase()):t})}function y(t){return i(t,function(t){return H.test(t)?"xn--"+p(t):t})}var x="object"==typeof n&&n,d="object"==typeof r&&r&&r.exports==x&&r,g="object"==typeof e&&e;(g.global===g||g.window===g)&&(o=g);var b,O,I=2147483647,j=36,w=1,A=26,R=38,E=700,q=72,P=128,S="-",T=/^xn--/,H=/[^ -~]/,C=/\x2E|\u3002|\uFF0E|\uFF61/g,U={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},L=j-w,Q=Math.floor,D=String.fromCharCode;if(b={version:"1.2.4",ucs2:{decode:u,encode:h},decode:m,encode:p,toASCII:y,toUnicode:v},"function"==typeof t&&"object"==typeof t.amd&&t.amd)t("punycode",function(){return b});else if(x&&!x.nodeType)if(d)d.exports=b;else for(O in b)b.hasOwnProperty(O)&&(x[O]=b[O]);else o.punycode=b}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(t,e){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,o,a){e=e||"&",o=o||"=";var s={};if("string"!=typeof t||0===t.length)return s;var i=/\+/g;t=t.split(e);var u=1e3;a&&"number"==typeof a.maxKeys&&(u=a.maxKeys);var h=t.length;u>0&&h>u&&(h=u);for(var l=0;h>l;++l){var c,f,m,p,v=t[l].replace(i,"%20"),y=v.indexOf(o);y>=0?(c=v.substr(0,y),f=v.substr(y+1)):(c=v,f=""),m=decodeURIComponent(c),p=decodeURIComponent(f),r(s,m)?n(s[m])?s[m].push(p):s[m]=[s[m],p]:s[m]=p}return s};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],20:[function(t,e){"use strict";function r(t,e){if(t.map)return t.map(e);for(var r=[],n=0;n",'"',"`"," ","\r","\n"," "],y=["{","}","|","\\","^","`"].concat(v),x=["'"].concat(y),d=["%","/","?",";","#"].concat(x),g=["/","?","#"],b=255,O=/^[a-z0-9A-Z_-]{0,63}$/,I=/^([a-z0-9A-Z_-]{0,63})(.*)$/,j={javascript:!0,"javascript:":!0},w={javascript:!0,"javascript:":!0},A={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},R=t("querystring");n.prototype.parse=function(t,e,r){if(!u(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var n=t;n=n.trim();var o=m.exec(n);if(o){o=o[0];var a=o.toLowerCase();this.protocol=a,n=n.substr(o.length)}if(r||o||n.match(/^\/\/[^@\/]+@[^@\/]+/)){var s="//"===n.substr(0,2);!s||o&&w[o]||(n=n.substr(2),this.slashes=!0)}if(!w[o]&&(s||o&&!A[o])){for(var i=-1,h=0;hl)&&(i=l)}var c,p;p=-1===i?n.lastIndexOf("@"):n.lastIndexOf("@",i),-1!==p&&(c=n.slice(0,p),n=n.slice(p+1),this.auth=decodeURIComponent(c)),i=-1;for(var h=0;hl)&&(i=l)}-1===i&&(i=n.length),this.host=n.slice(0,i),n=n.slice(i),this.parseHost(),this.hostname=this.hostname||"";var v="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!v)for(var y=this.hostname.split(/\./),h=0,E=y.length;E>h;h++){var q=y[h];if(q&&!q.match(O)){for(var P="",S=0,T=q.length;T>S;S++)P+=q.charCodeAt(S)>127?"x":q[S];if(!P.match(O)){var H=y.slice(0,h),C=y.slice(h+1),U=q.match(I);U&&(H.push(U[1]),C.unshift(U[2])),C.length&&(n="/"+C.join(".")+n),this.hostname=H.join(".");break}}}if(this.hostname=this.hostname.length>b?"":this.hostname.toLowerCase(),!v){for(var L=this.hostname.split("."),Q=[],h=0;hh;h++){var B=x[h],k=encodeURIComponent(B);k===B&&(k=escape(B)),n=n.split(B).join(k)}var F=n.indexOf("#");-1!==F&&(this.hash=n.substr(F),n=n.slice(0,F));var V=n.indexOf("?");if(-1!==V?(this.search=n.substr(V),this.query=n.substr(V+1),e&&(this.query=R.parse(this.query)),n=n.slice(0,V)):e&&(this.search="",this.query={}),n&&(this.pathname=n),A[a]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var _=this.pathname||"",D=this.search||"";this.path=_+D}return this.href=this.format(),this},n.prototype.format=function(){var t=this.auth||"";t&&(t=encodeURIComponent(t),t=t.replace(/%3A/i,":"),t+="@");var e=this.protocol||"",r=this.pathname||"",n=this.hash||"",o=!1,a="";this.host?o=t+this.host:this.hostname&&(o=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&h(this.query)&&Object.keys(this.query).length&&(a=R.stringify(this.query));var s=this.search||a&&"?"+a||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||A[e])&&o!==!1?(o="//"+(o||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):o||(o=""),n&&"#"!==n.charAt(0)&&(n="#"+n),s&&"?"!==s.charAt(0)&&(s="?"+s),r=r.replace(/[?#]/g,function(t){return encodeURIComponent(t)}),s=s.replace("#","%23"),e+o+r+s+n},n.prototype.resolve=function(t){return this.resolveObject(o(t,!1,!0)).format()},n.prototype.resolveObject=function(t){if(u(t)){var e=new n;e.parse(t,!1,!0),t=e}var r=new n;if(Object.keys(this).forEach(function(t){r[t]=this[t]},this),r.hash=t.hash,""===t.href)return r.href=r.format(),r;if(t.slashes&&!t.protocol)return Object.keys(t).forEach(function(e){"protocol"!==e&&(r[e]=t[e])}),A[r.protocol]&&r.hostname&&!r.pathname&&(r.path=r.pathname="/"),r.href=r.format(),r;if(t.protocol&&t.protocol!==r.protocol){if(!A[t.protocol])return Object.keys(t).forEach(function(e){r[e]=t[e]}),r.href=r.format(),r;if(r.protocol=t.protocol,t.host||w[t.protocol])r.pathname=t.pathname;else{for(var o=(t.pathname||"").split("/");o.length&&!(t.host=o.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==o[0]&&o.unshift(""),o.length<2&&o.unshift(""),r.pathname=o.join("/")}if(r.search=t.search,r.query=t.query,r.host=t.host||"",r.auth=t.auth,r.hostname=t.hostname||t.host,r.port=t.port,r.pathname||r.search){var a=r.pathname||"",s=r.search||"";r.path=a+s}return r.slashes=r.slashes||t.slashes,r.href=r.format(),r}var i=r.pathname&&"/"===r.pathname.charAt(0),h=t.host||t.pathname&&"/"===t.pathname.charAt(0),f=h||i||r.host&&t.pathname,m=f,p=r.pathname&&r.pathname.split("/")||[],o=t.pathname&&t.pathname.split("/")||[],v=r.protocol&&!A[r.protocol];if(v&&(r.hostname="",r.port=null,r.host&&(""===p[0]?p[0]=r.host:p.unshift(r.host)),r.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===o[0]?o[0]=t.host:o.unshift(t.host)),t.host=null),f=f&&(""===o[0]||""===p[0])),h)r.host=t.host||""===t.host?t.host:r.host,r.hostname=t.hostname||""===t.hostname?t.hostname:r.hostname,r.search=t.search,r.query=t.query,p=o;else if(o.length)p||(p=[]),p.pop(),p=p.concat(o),r.search=t.search,r.query=t.query;else if(!c(t.search)){if(v){r.hostname=r.host=p.shift();var y=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;y&&(r.auth=y.shift(),r.host=r.hostname=y.shift())}return r.search=t.search,r.query=t.query,l(r.pathname)&&l(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!p.length)return r.pathname=null,r.path=r.search?"/"+r.search:null,r.href=r.format(),r;for(var x=p.slice(-1)[0],d=(r.host||t.host)&&("."===x||".."===x)||""===x,g=0,b=p.length;b>=0;b--)x=p[b],"."==x?p.splice(b,1):".."===x?(p.splice(b,1),g++):g&&(p.splice(b,1),g--);if(!f&&!m)for(;g--;g)p.unshift("..");!f||""===p[0]||p[0]&&"/"===p[0].charAt(0)||p.unshift(""),d&&"/"!==p.join("/").substr(-1)&&p.push("");var O=""===p[0]||p[0]&&"/"===p[0].charAt(0);if(v){r.hostname=r.host=O?"":p.length?p.shift():"";var y=r.host&&r.host.indexOf("@")>0?r.host.split("@"):!1;y&&(r.auth=y.shift(),r.host=r.hostname=y.shift())}return f=f||r.host&&p.length,f&&!O&&p.unshift(""),p.length?r.pathname=p.join("/"):(r.pathname=null,r.path=null),l(r.pathname)&&l(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},n.prototype.parseHost=function(){var t=this.host,e=p.exec(t);e&&(e=e[0],":"!==e&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},{punycode:18,querystring:21}]},{},[17])(17)}); \ No newline at end of file diff --git a/cli.js b/cli.js index 426a0ae..834588d 100755 --- a/cli.js +++ b/cli.js @@ -70,6 +70,7 @@ var mainOptions = { caseSensitive: [[false, 'Treat attributes in case sensitive manner (useful for SVG; e.g. viewBox)']], minifyJS: [[false, 'Minify Javascript in script elements and on* attributes (uses UglifyJS)']], minifyCSS: [[false, 'Minify CSS in style elements and style attributes (uses clean-css)']], + minifyURLs: [[false, 'Minify URLs in various attributes (uses relateurl)']], ignoreCustomComments: [[false, 'Array of regex\'es that allow to ignore certain comments, when matched', 'string'], 'json'], processScripts: [[false, 'Array of strings corresponding to types of script elements to process through minifier (e.g. "text/ng-template", "text/x-handlebars-template", etc.)', 'string'], 'json'], maxLineLength: [[false, 'Max line length', 'number'], true] diff --git a/dist/htmlminifier.js b/dist/htmlminifier.js index 17e9117..aeb087b 100644 --- a/dist/htmlminifier.js +++ b/dist/htmlminifier.js @@ -746,7 +746,14 @@ else if (attrName === 'class') { return collapseWhitespace(trimWhitespace(attrValue)); } - else if (isUriTypeAttribute(attrName, tag) || isNumberTypeAttribute(attrName, tag)) { + else if (isUriTypeAttribute(attrName, tag)) { + attrValue = trimWhitespace(attrValue); + if (options.minifyURLs) { + return minifyURLs(attrValue, options.minifyURLs); + } + return attrValue; + } + else if (isNumberTypeAttribute(attrName, tag)) { return trimWhitespace(attrValue); } else if (attrName === 'style') { @@ -901,6 +908,37 @@ } } + function minifyURLs(text, options) { + if (typeof options !== 'object') { + options = { }; + } + + try { + // try to get global reference first + var __RelateUrl = global.RelateUrl; + + if (typeof __RelateUrl === 'undefined' && typeof require === 'function') { + __RelateUrl = require('relateurl'); + } + + // noop + if (!__RelateUrl) { + return text; + } + + if (__RelateUrl.relate) { + return __RelateUrl.relate(text, options); + } + else { + return text; + } + } + catch (err) { + log(err); + } + return text; + } + function minifyJS(text, options) { if (typeof options !== 'object') { options = { }; diff --git a/dist/htmlminifier.min.js b/dist/htmlminifier.min.js index c1f5c30..0a78451 100644 --- a/dist/htmlminifier.min.js +++ b/dist/htmlminifier.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2014 Juriy "kangax" Zaytsev * Licensed under MIT (https://github.com/kangax/html-minifier/blob/gh-pages/LICENSE) */ -!function(a){"use strict";function b(a){var b,c=new RegExp("(?:\\s*[\\w:-]+(?:\\s*(?:"+d(a)+")\\s*(?:(?:\"[^\"]*\")|(?:'[^']*')|[^>\\s]+))?)*");if(a.customAttrSurround){for(var e=[],f=a.customAttrSurround.length-1;f>=0;f--)e[f]="(?:\\s*"+a.customAttrSurround[f][0].source+c.source+a.customAttrSurround[f][1].source+")";e.unshift(c.source),b=new RegExp("((?:"+e.join("|")+")*)")}else b=new RegExp("("+c.source+")");return new RegExp(j.source+b.source+k.source)}function c(a){var b=new RegExp(f.source+"(?:\\s*("+d(a)+")\\s*(?:"+i.join("|")+"))?");if(a.customAttrSurround){for(var c=[],e=a.customAttrSurround.length-1;e>=0;e--)c[e]="(?:("+a.customAttrSurround[e][0].source+")"+b.source+"("+a.customAttrSurround[e][1].source+"))";return c.unshift("(?:"+b.source+")"),new RegExp(c.join("|"),"g")}return new RegExp(b.source,"g")}function d(a){return h.concat(a.customAttrAssign||[]).map(function(a){return"(?:"+a.source+")"}).join("|")}function e(a){for(var b={},c=a.split(","),d=0;d\s]+)/.source],j=/^<([\w:-]+)/,k=/\s*(\/?)>/,l=/^<\/([\w:-]+)[^>]*>/,m=/\/>$/,n=/^]+>/i,o=/<(%|\?)/,p=/(%|\?)>/,q=!1;"x".replace(/x(.)?/g,function(a,b){q=""===b});var r,s,t,u=e("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,wbr"),v=e("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,noscript,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,svg,textarea,tt,u,var"),w=e("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"),x=e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),y=e("script,style,noscript"),z={},A=a.HTMLParser=function(a,d){function e(a,b,c,e){for(var g=!1;!d.html5&&A.last()&&v[A.last()];)f("",A.last());if(w[b]&&A.last()===b&&f("",b),e=u[b]||!!e,e?g=a.match(m):A.push(b),d.start){var h=[];c.replace(D,function(){var a,b,c,e,f,g,i=7;if(q&&-1===arguments[0].indexOf('""')&&(""===arguments[3]&&(arguments[3]=void 0),""===arguments[4]&&(arguments[4]=void 0),""===arguments[5]&&(arguments[5]=void 0)),a=arguments[1])g=arguments[2],c=arguments[3],b=c||arguments[4]||arguments[5];else if(d.customAttrSurround)for(var j=d.customAttrSurround.length-1;j>=0;j--)if(a=arguments[j*i+7],g=arguments[j*i+8],a){c=arguments[j*i+9],b=c||arguments[j*i+10]||arguments[j*i+11],e=arguments[j*i+6],f=arguments[j*i+12];break}void 0===b&&(b=x[a]?a:c),h.push({name:a,value:b,escaped:b&&b.replace(/(^|[^\\])"/g,"$1""),customAssign:g||"=",customOpen:e||"",customClose:f||""})}),d.start&&d.start(b,h,e,g)}}function f(a,b){var c;if(b)for(c=A.length-1;c>=0&&A[c].toLowerCase()!==b;c--);else c=0;if(c>=0){for(var e=A.length-1;e>=c;e--)d.end&&d.end(A[e]);A.length=c}}var g,h,i,j,k,A=[],B=a;A.last=function(){return this[this.length-1]};for(var C=b(d),D=c(d);a;){if(h=!0,A.last()&&y[A.last()])r=A.last().toLowerCase(),s=z[r]||(z[r]=new RegExp("([\\s\\S]*?)]*>","i")),a=a.replace(s,function(a,b){return"script"!==r&&"style"!==r&&"noscript"!==r&&(b=b.replace(//g,"$1").replace(//g,"$1")),d.chars&&d.chars(b),""}),f("",r);else if(0===a.indexOf(""),g>=0&&(d.comment&&d.comment(a.substring(4,g)),a=a.substring(g+3),h=!1)),0===a.indexOf(""),g>=0&&(d.comment&&d.comment(a.substring(2,g+1),!0),a=a.substring(g+2),h=!1)):0===a.search(o)?(g=a.search(p),g>=0&&(d.ignore&&d.ignore(a.substring(0,g+2)),a=a.substring(g+2),h=!1)):(i=n.exec(a))?(d.doctype&&d.doctype(i[0]),a=a.substring(i[0].length),h=!1):0===a.indexOf("g?a:a.substring(0,g);a=0>g?"":a.substring(g),t=a.match(C),t?k=t[1]:(t=a.match(l),k=t?"/"+t[1]:""),d.chars&&d.chars(E,j,k)}if(a===B)throw"Parse Error: "+a;B=a}f()};a.HTMLtoXML=function(a){var b="";return new A(a,{start:function(a,c,d){b+="<"+a;for(var e=0;e"},end:function(a){b+=""},chars:function(a){b+=a},comment:function(a){b+=""},ignore:function(a){b+=a}}),b},a.HTMLtoDOM=function(a,b){var c=e("html,head,body,title"),d={link:"head",base:"head"};b?b=b.ownerDocument||b.getOwnerDocument&&b.getOwnerDocument()||b:"undefined"!=typeof DOMDocument?b=new DOMDocument:"undefined"!=typeof document&&document.implementation&&document.implementation.createDocument?b=document.implementation.createDocument("","",null):"undefined"!=typeof ActiveX&&(b=new ActiveXObject("Msxml.DOMDocument"));var f=[],g=b.documentElement||b.getDocumentElement&&b.getDocumentElement();if(!g&&b.createElement&&!function(){var a=b.createElement("html"),c=b.createElement("head");c.appendChild(b.createElement("title")),a.appendChild(c),a.appendChild(b.createElement("body")),b.appendChild(a)}(),b.getElementsByTagName)for(var h in c)c[h]=b.getElementsByTagName(h)[0];var i=c.body;return new A(a,{start:function(a,e,g){if(c[a])return void(i=c[a]);var h=b.createElement(a);for(var j in e)h.setAttribute(e[j].name,e[j].value);d[a]&&"boolean"!=typeof c[d[a]]?c[d[a]].appendChild(h):i&&i.appendChild&&i.appendChild(h),g||(f.push(h),i=h)},end:function(){f.length-=1,i=f[f.length-1]},chars:function(a){i.appendChild(b.createTextNode(a))},comment:function(){},ignore:function(){}}),b}}("undefined"==typeof exports?this:exports),function(a){"use strict";function b(a){return a?a.replace(/[\t\n\r ]+/g," "):a}function c(a,b,c,d){var e=["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","svg","time","tt","u","var"];return b&&"img"!==b&&"input"!==b&&("/"!==b.substr(0,1)||"/"===b.substr(0,1)&&-1===e.indexOf(b.substr(1)))&&(a=a.replace(/^\s+/,d.conservativeCollapse?" ":"")),c&&"img"!==c&&"input"!==c&&("/"===c.substr(0,1)||"/"!==c.substr(0,1)&&-1===e.indexOf(c))&&(a=a.replace(/\s+$/,d.conservativeCollapse?" ":"")),b&&c?a.replace(/[\t\n\r]+/g," ").replace(/[ ]+/g," "):a}function d(a){return/\[if[^\]]+\]/.test(a)||/\s*((?:c;c++)if(b.ignoreCustomComments[c].test(a))return!0;return!1}function f(a){return/^on[a-z]+/.test(a)}function g(a){return/^[^\x20\t\n\f\r"'`=<>]+$/.test(a)&&!/\/$/.test(a)&&!/\/$/.test(a)}function h(a,b){for(var c=a.length;c--;)if(a[c].name.toLowerCase()===b)return!0;return!1}function i(a,b,c,d){return c=c?I(c.toLowerCase()):"","script"===a&&"language"===b&&"javascript"===c||"form"===a&&"method"===b&&"get"===c||"input"===a&&"type"===b&&"text"===c||"script"===a&&"charset"===b&&!h(d,"src")||"a"===a&&"name"===b&&h(d,"id")||"area"===a&&"shape"===b&&"rect"===c}function j(a,b,c){return"script"===a&&"type"===b&&"text/javascript"===I(c.toLowerCase())}function k(a,b,c){return("style"===a||"link"===a)&&"type"===b&&"text/css"===I(c.toLowerCase())}function l(a){return/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|truespeed|typemustmatch|visible)$/.test(a)}function m(a,b){return/^(?:a|area|link|base)$/.test(b)&&"href"===a||"img"===b&&/^(?:src|longdesc|usemap)$/.test(a)||"object"===b&&/^(?:classid|codebase|data|usemap)$/.test(a)||"q"===b&&"cite"===a||"blockquote"===b&&"cite"===a||("ins"===b||"del"===b)&&"cite"===a||"form"===b&&"action"===a||"input"===b&&("src"===a||"usemap"===a)||"head"===b&&"profile"===a||"script"===b&&("src"===a||"for"===a)}function n(a,b){return/^(?:a|area|object|button)$/.test(b)&&"tabindex"===a||"input"===b&&("maxlength"===a||"tabindex"===a)||"select"===b&&("size"===a||"tabindex"===a)||"textarea"===b&&/^(?:rows|cols|tabindex)$/.test(a)||"colgroup"===b&&"span"===a||"col"===b&&"span"===a||("th"===b||"td"===b)&&("rowspan"===a||"colspan"===a)}function o(a,c,d,e,g){if(d&&f(c)){if(d=I(d).replace(/^javascript:\s*/i,"").replace(/\s*;$/,""),e.minifyJS){var h="(function(){"+d+"})()",i=C(h,e.minifyJS);return i.slice(12,i.length-4).replace(/"/g,""")}return d}return"class"===c?b(I(d)):m(c,a)||n(c,a)?I(d):"style"===c?(d=I(d).replace(/\s*;\s*$/,""),e.minifyCSS?D(d,e.minifyCSS):d):(p(a,g)&&"content"===c&&(d=d.replace(/1\.0/g,"1").replace(/\s+/g,"")),d)}function p(a,b){if("meta"!==a)return!1;for(var c=0,d=b.length;d>c;c++)if("name"===b[c].name&&"viewport"===b[c].value)return!0}function q(a){return a.replace(/^(\[[^\]]+\]>)\s*/,"$1").replace(/\s*(\s*\*\/|\/\/\s*\]\]>)\s*$/,"")}function s(a,b,c){for(var d=0,e=c.length;e>d;d++)if("type"===c[d].name.toLowerCase()&&b.processScripts.indexOf(c[d].value)>-1)return E(a,b);return a}function t(a,b){return a.replace(J[b],"").replace(K[b],"")}function u(a){return/^(?:html|t?body|t?head|tfoot|tr|td|th|dt|dd|option|colgroup|source)$/.test(a)}function v(a,b,c){var d=/^(["'])?\s*\1$/.test(c);return d?"input"===a&&"value"===b||L.test(b):!1}function w(a){return"textarea"!==a}function x(a){return!/^(?:script|style|pre|textarea)$/.test(a)}function y(a){return!/^(?:pre|textarea)$/.test(a)}function z(a){for(var b="",c=0,d=a.length;d>c;c++)b+=" "+a[c].name+(l(a[c].value)?"":'="'+a[c].value+'"');return b}function A(a,b,c,d){var e,f=d.caseSensitive?a.name:a.name.toLowerCase(),h=a.escaped;return d.removeRedundantAttributes&&i(c,f,h,b)||d.removeScriptTypeAttributes&&j(c,f,h)||d.removeStyleLinkTypeAttributes&&k(c,f,h)?"":(h=o(c,f,h,d,b),(void 0!==h&&!d.removeAttributeQuotes||!g(h))&&(h='"'+h+'"'),d.removeEmptyAttributes&&v(c,f,h)?"":(e=void 0===h||d.collapseBooleanAttributes&&l(f)?f:f+a.customAssign+h," "+a.customOpen+e+a.customClose))}function B(a){for(var b=["canCollapseWhitespace","canTrimWhitespace"],c=0,d=b.length;d>c;c++)a[b[c]]||(a[b[c]]=function(){return!1})}function C(b,c){"object"!=typeof c&&(c={}),c.fromString=!0,c.output={inline_script:!0};try{var d=a.UglifyJS;if("undefined"==typeof d&&"function"==typeof require&&(d=require("uglify-js")),!d)return b;if(d.minify)return d.minify(b,c).code;if(d.parse){var e=d.parse(b);e.figure_out_scope();var f=d.Compressor(),g=e.transform(f);g.figure_out_scope(),g.compute_char_frequency(),c.mangle!==!1&&g.mangle_names();var h=d.OutputStream(c.output);return g.print(h),h.toString()}return b}catch(i){G(i)}return b}function D(a,b){"object"!=typeof b&&(b={}),"undefined"==typeof b.noAdvanced&&(b.noAdvanced=!0);try{if("undefined"!=typeof CleanCSS)return new CleanCSS(b).minify(a);if("function"==typeof require){var c=require("clean-css");return new c(b).minify(a)}}catch(d){G(d)}return a}function E(a,f){function g(a,b){return x(a)||f.canCollapseWhitespace(a,b)}function h(a,b){return y(a)||f.canTrimWhitespace(a,b)}f=f||{},a=I(a),B(f);var i=[],j=[],k="",l="",m=[],n=[],o=[],p=f.lint,v=!1,E=new Date;new H(a,{html5:"undefined"!=typeof f.html5?f.html5:!0,start:function(a,b,c,d){if(v)return void j.push("<"+a,z(b),d?"/":"",">");a=f.caseSensitive?a:a.toLowerCase(),l=a,k="",m=b,f.collapseWhitespace&&(h(a,b)||n.push(a),g(a,b)||o.push(a));var e="<"+a,i=(d&&f.keepClosingSlash?"/":"")+">";0===b.length&&(e+=i),j.push(e),p&&p.testElement(a);for(var q,r=0,s=b.length;s>r;r++)p&&p.testAttribute(a,b[r].name.toLowerCase(),b[r].escaped),q=A(b[r],b,a,f),r===s-1&&(q+=i),j.push(q)},end:function(a){if(v)return void j.push("");f.collapseWhitespace&&(n.length&&a===n[n.length-1]&&n.pop(),o.length&&a===o[o.length-1]&&o.pop());var b=""===k&&a===l;if(f.removeEmptyElements&&b&&w(a)){for(var c=j.length-1;c>=0;c--)if(/^<[^\/!]/.test(j[c])){j.splice(c);break}}else f.removeOptionalTags&&u(a)||(j.push(""),i.push.apply(i,j),j.length=0,k="")},chars:function(a,d,e){return v?void j.push(a):(("script"===l||"style"===l)&&(f.removeCommentsFromCDATA&&(a=t(a,l)),f.removeCDATASectionsFromCDATA&&(a=r(a)),f.processScripts&&(a=s(a,f,m))),"script"===l&&f.minifyJS&&(a=C(a,f.minifyJS)),"style"===l&&f.minifyCSS&&(a=D(a,f.minifyCSS)),f.collapseWhitespace&&(n.length||(a=d||e?c(a,d,e,f):I(a)),o.length||(a=b(a))),k=a,p&&p.testChars(a),void j.push(a))},comment:function(a,b){var c=b?"":"-->";return/^\s*htmlmin:ignore/.test(a)?(v=!v,void j.push("")):(a=f.removeComments?d(a)?c+q(a)+g:e(a,f)?"":"":c+a+g,void j.push(a))},ignore:function(a){j.push(f.removeIgnored?"":a)},doctype:function(a){j.push(f.useShortDoctype?"":b(a))},customAttrAssign:f.customAttrAssign,customAttrSurround:f.customAttrSurround}),i.push.apply(i,j);var J=F(i,f);return G("minified in: "+(new Date-E)+"ms"),J}function F(a,b){var c,d=b.maxLineLength;if(d){for(var e,f=[],g="",h=0,i=a.length;i>h;h++)e=a[h],g.length+e.length\s*$/,style:/\s*-->\s*$/},L=new RegExp("^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(?:down|up|over|move|out)|key(?:press|down|up)))$");"undefined"!=typeof exports?exports.minify=E:a.minify=E}(this),function(a){"use strict";function b(a){return/^(?:big|small|hr|blink|marquee)$/.test(a)}function c(a){return/^(?:applet|basefont|center|dir|font|isindex|strike)$/.test(a)}function d(a){return/^on[a-z]+/.test(a)}function e(a){return"style"===a.toLowerCase()}function f(a,b){return"align"===b&&/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(a)||"alink"===b&&"body"===a||"alt"===b&&"applet"===a||"archive"===b&&"applet"===a||"background"===b&&"body"===a||"bgcolor"===b&&/^(?:table|t[rdh]|body)$/.test(a)||"border"===b&&/^(?:img|object)$/.test(a)||"clear"===b&&"br"===a||"code"===b&&"applet"===a||"codebase"===b&&"applet"===a||"color"===b&&/^(?:base(?:font)?)$/.test(a)||"compact"===b&&/^(?:dir|[dou]l|menu)$/.test(a)||"face"===b&&/^base(?:font)?$/.test(a)||"height"===b&&/^(?:t[dh]|applet)$/.test(a)||"hspace"===b&&/^(?:applet|img|object)$/.test(a)||"language"===b&&"script"===a||"link"===b&&"body"===a||"name"===b&&"applet"===a||"noshade"===b&&"hr"===a||"nowrap"===b&&/^t[dh]$/.test(a)||"object"===b&&"applet"===a||"prompt"===b&&"isindex"===a||"size"===b&&/^(?:hr|font|basefont)$/.test(a)||"start"===b&&"ol"===a||"text"===b&&"body"===a||"type"===b&&/^(?:li|ol|ul)$/.test(a)||"value"===b&&"li"===a||"version"===b&&"html"===a||"vlink"===b&&"body"===a||"vspace"===b&&/^(?:applet|img|object)$/.test(a)||"width"===b&&/^(?:hr|td|th|applet|pre)$/.test(a)}function g(a,b){return"href"===a&&/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(b)}function h(){this.log=[],this._lastElement=null,this._isElementRepeated=!1}h.prototype.testElement=function(a){c(a)?this.log.push('Found deprecated <'+a+"> element"):b(a)?this.log.push('Found presentational <'+a+"> element"):this.checkRepeatingElement(a)},h.prototype.checkRepeatingElement=function(a){"br"===a&&"br"===this._lastElement?this._isElementRepeated=!0:this._isElementRepeated&&(this._reportRepeatingElement(),this._isElementRepeated=!1),this._lastElement=a},h.prototype._reportRepeatingElement=function(){this.log.push("Found <br> sequence. Try replacing it with styling.")},h.prototype.testAttribute=function(a,b,c){d(b)?this.log.push('Found event attribute ('+b+") on <"+a+"> element."):f(a,b)?this.log.push('Found deprecated '+b+" attribute on <"+a+"> element."):e(b)?this.log.push('Found style attribute on <'+a+"> element."):g(b,c)&&this.log.push('Found inaccessible attribute (on <'+a+"> element).")},h.prototype.testChars=function(a){this._lastElement="",/( \s*){2,}/.test(a)&&this.log.push("Found repeating &nbsp; sequence. Try replacing it with styling.")},h.prototype.test=function(a,b,c){this.testElement(a),this.testAttribute(a,b,c)},h.prototype.populate=function(a){if(this._isElementRepeated&&this._reportRepeatingElement(),this.log.length)if(a)a.innerHTML="
  1. "+this.log.join("
  2. ")+"
";else{var b=" - "+this.log.join("\n - ").replace(/(<([^>]+)>)/gi,"").replace(/</g,"<").replace(/>/g,">");console.log(b)}},a.HTMLLint=h}("undefined"==typeof exports?this:exports); \ No newline at end of file +!function(a){"use strict";function b(a){var b,c=new RegExp("(?:\\s*[\\w:-]+(?:\\s*(?:"+d(a)+")\\s*(?:(?:\"[^\"]*\")|(?:'[^']*')|[^>\\s]+))?)*");if(a.customAttrSurround){for(var e=[],f=a.customAttrSurround.length-1;f>=0;f--)e[f]="(?:\\s*"+a.customAttrSurround[f][0].source+c.source+a.customAttrSurround[f][1].source+")";e.unshift(c.source),b=new RegExp("((?:"+e.join("|")+")*)")}else b=new RegExp("("+c.source+")");return new RegExp(j.source+b.source+k.source)}function c(a){var b=new RegExp(f.source+"(?:\\s*("+d(a)+")\\s*(?:"+i.join("|")+"))?");if(a.customAttrSurround){for(var c=[],e=a.customAttrSurround.length-1;e>=0;e--)c[e]="(?:("+a.customAttrSurround[e][0].source+")"+b.source+"("+a.customAttrSurround[e][1].source+"))";return c.unshift("(?:"+b.source+")"),new RegExp(c.join("|"),"g")}return new RegExp(b.source,"g")}function d(a){return h.concat(a.customAttrAssign||[]).map(function(a){return"(?:"+a.source+")"}).join("|")}function e(a){for(var b={},c=a.split(","),d=0;d\s]+)/.source],j=/^<([\w:-]+)/,k=/\s*(\/?)>/,l=/^<\/([\w:-]+)[^>]*>/,m=/\/>$/,n=/^]+>/i,o=/<(%|\?)/,p=/(%|\?)>/,q=!1;"x".replace(/x(.)?/g,function(a,b){q=""===b});var r,s,t,u=e("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,wbr"),v=e("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,noscript,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,svg,textarea,tt,u,var"),w=e("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source"),x=e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),y=e("script,style,noscript"),z={},A=a.HTMLParser=function(a,d){function e(a,b,c,e){for(var g=!1;!d.html5&&A.last()&&v[A.last()];)f("",A.last());if(w[b]&&A.last()===b&&f("",b),e=u[b]||!!e,e?g=a.match(m):A.push(b),d.start){var h=[];c.replace(D,function(){var a,b,c,e,f,g,i=7;if(q&&-1===arguments[0].indexOf('""')&&(""===arguments[3]&&(arguments[3]=void 0),""===arguments[4]&&(arguments[4]=void 0),""===arguments[5]&&(arguments[5]=void 0)),a=arguments[1])g=arguments[2],c=arguments[3],b=c||arguments[4]||arguments[5];else if(d.customAttrSurround)for(var j=d.customAttrSurround.length-1;j>=0;j--)if(a=arguments[j*i+7],g=arguments[j*i+8],a){c=arguments[j*i+9],b=c||arguments[j*i+10]||arguments[j*i+11],e=arguments[j*i+6],f=arguments[j*i+12];break}void 0===b&&(b=x[a]?a:c),h.push({name:a,value:b,escaped:b&&b.replace(/(^|[^\\])"/g,"$1""),customAssign:g||"=",customOpen:e||"",customClose:f||""})}),d.start&&d.start(b,h,e,g)}}function f(a,b){var c;if(b)for(c=A.length-1;c>=0&&A[c].toLowerCase()!==b;c--);else c=0;if(c>=0){for(var e=A.length-1;e>=c;e--)d.end&&d.end(A[e]);A.length=c}}var g,h,i,j,k,A=[],B=a;A.last=function(){return this[this.length-1]};for(var C=b(d),D=c(d);a;){if(h=!0,A.last()&&y[A.last()])r=A.last().toLowerCase(),s=z[r]||(z[r]=new RegExp("([\\s\\S]*?)]*>","i")),a=a.replace(s,function(a,b){return"script"!==r&&"style"!==r&&"noscript"!==r&&(b=b.replace(//g,"$1").replace(//g,"$1")),d.chars&&d.chars(b),""}),f("",r);else if(0===a.indexOf(""),g>=0&&(d.comment&&d.comment(a.substring(4,g)),a=a.substring(g+3),h=!1)),0===a.indexOf(""),g>=0&&(d.comment&&d.comment(a.substring(2,g+1),!0),a=a.substring(g+2),h=!1)):0===a.search(o)?(g=a.search(p),g>=0&&(d.ignore&&d.ignore(a.substring(0,g+2)),a=a.substring(g+2),h=!1)):(i=n.exec(a))?(d.doctype&&d.doctype(i[0]),a=a.substring(i[0].length),h=!1):0===a.indexOf("g?a:a.substring(0,g);a=0>g?"":a.substring(g),t=a.match(C),t?k=t[1]:(t=a.match(l),k=t?"/"+t[1]:""),d.chars&&d.chars(E,j,k)}if(a===B)throw"Parse Error: "+a;B=a}f()};a.HTMLtoXML=function(a){var b="";return new A(a,{start:function(a,c,d){b+="<"+a;for(var e=0;e"},end:function(a){b+=""},chars:function(a){b+=a},comment:function(a){b+=""},ignore:function(a){b+=a}}),b},a.HTMLtoDOM=function(a,b){var c=e("html,head,body,title"),d={link:"head",base:"head"};b?b=b.ownerDocument||b.getOwnerDocument&&b.getOwnerDocument()||b:"undefined"!=typeof DOMDocument?b=new DOMDocument:"undefined"!=typeof document&&document.implementation&&document.implementation.createDocument?b=document.implementation.createDocument("","",null):"undefined"!=typeof ActiveX&&(b=new ActiveXObject("Msxml.DOMDocument"));var f=[],g=b.documentElement||b.getDocumentElement&&b.getDocumentElement();if(!g&&b.createElement&&!function(){var a=b.createElement("html"),c=b.createElement("head");c.appendChild(b.createElement("title")),a.appendChild(c),a.appendChild(b.createElement("body")),b.appendChild(a)}(),b.getElementsByTagName)for(var h in c)c[h]=b.getElementsByTagName(h)[0];var i=c.body;return new A(a,{start:function(a,e,g){if(c[a])return void(i=c[a]);var h=b.createElement(a);for(var j in e)h.setAttribute(e[j].name,e[j].value);d[a]&&"boolean"!=typeof c[d[a]]?c[d[a]].appendChild(h):i&&i.appendChild&&i.appendChild(h),g||(f.push(h),i=h)},end:function(){f.length-=1,i=f[f.length-1]},chars:function(a){i.appendChild(b.createTextNode(a))},comment:function(){},ignore:function(){}}),b}}("undefined"==typeof exports?this:exports),function(a){"use strict";function b(a){return a?a.replace(/[\t\n\r ]+/g," "):a}function c(a,b,c,d){var e=["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","svg","time","tt","u","var"];return b&&"img"!==b&&"input"!==b&&("/"!==b.substr(0,1)||"/"===b.substr(0,1)&&-1===e.indexOf(b.substr(1)))&&(a=a.replace(/^\s+/,d.conservativeCollapse?" ":"")),c&&"img"!==c&&"input"!==c&&("/"===c.substr(0,1)||"/"!==c.substr(0,1)&&-1===e.indexOf(c))&&(a=a.replace(/\s+$/,d.conservativeCollapse?" ":"")),b&&c?a.replace(/[\t\n\r]+/g," ").replace(/[ ]+/g," "):a}function d(a){return/\[if[^\]]+\]/.test(a)||/\s*((?:c;c++)if(b.ignoreCustomComments[c].test(a))return!0;return!1}function f(a){return/^on[a-z]+/.test(a)}function g(a){return/^[^\x20\t\n\f\r"'`=<>]+$/.test(a)&&!/\/$/.test(a)&&!/\/$/.test(a)}function h(a,b){for(var c=a.length;c--;)if(a[c].name.toLowerCase()===b)return!0;return!1}function i(a,b,c,d){return c=c?J(c.toLowerCase()):"","script"===a&&"language"===b&&"javascript"===c||"form"===a&&"method"===b&&"get"===c||"input"===a&&"type"===b&&"text"===c||"script"===a&&"charset"===b&&!h(d,"src")||"a"===a&&"name"===b&&h(d,"id")||"area"===a&&"shape"===b&&"rect"===c}function j(a,b,c){return"script"===a&&"type"===b&&"text/javascript"===J(c.toLowerCase())}function k(a,b,c){return("style"===a||"link"===a)&&"type"===b&&"text/css"===J(c.toLowerCase())}function l(a){return/^(?:allowfullscreen|async|autofocus|autoplay|checked|compact|controls|declare|default|defaultchecked|defaultmuted|defaultselected|defer|disabled|draggable|enabled|formnovalidate|hidden|indeterminate|inert|ismap|itemscope|loop|multiple|muted|nohref|noresize|noshade|novalidate|nowrap|open|pauseonexit|readonly|required|reversed|scoped|seamless|selected|sortable|spellcheck|truespeed|typemustmatch|visible)$/.test(a)}function m(a,b){return/^(?:a|area|link|base)$/.test(b)&&"href"===a||"img"===b&&/^(?:src|longdesc|usemap)$/.test(a)||"object"===b&&/^(?:classid|codebase|data|usemap)$/.test(a)||"q"===b&&"cite"===a||"blockquote"===b&&"cite"===a||("ins"===b||"del"===b)&&"cite"===a||"form"===b&&"action"===a||"input"===b&&("src"===a||"usemap"===a)||"head"===b&&"profile"===a||"script"===b&&("src"===a||"for"===a)}function n(a,b){return/^(?:a|area|object|button)$/.test(b)&&"tabindex"===a||"input"===b&&("maxlength"===a||"tabindex"===a)||"select"===b&&("size"===a||"tabindex"===a)||"textarea"===b&&/^(?:rows|cols|tabindex)$/.test(a)||"colgroup"===b&&"span"===a||"col"===b&&"span"===a||("th"===b||"td"===b)&&("rowspan"===a||"colspan"===a)}function o(a,c,d,e,g){if(d&&f(c)){if(d=J(d).replace(/^javascript:\s*/i,"").replace(/\s*;$/,""),e.minifyJS){var h="(function(){"+d+"})()",i=D(h,e.minifyJS);return i.slice(12,i.length-4).replace(/"/g,""")}return d}return"class"===c?b(J(d)):m(c,a)?(d=J(d),e.minifyURLs?C(d,e.minifyURLs):d):n(c,a)?J(d):"style"===c?(d=J(d).replace(/\s*;\s*$/,""),e.minifyCSS?E(d,e.minifyCSS):d):(p(a,g)&&"content"===c&&(d=d.replace(/1\.0/g,"1").replace(/\s+/g,"")),d)}function p(a,b){if("meta"!==a)return!1;for(var c=0,d=b.length;d>c;c++)if("name"===b[c].name&&"viewport"===b[c].value)return!0}function q(a){return a.replace(/^(\[[^\]]+\]>)\s*/,"$1").replace(/\s*(\s*\*\/|\/\/\s*\]\]>)\s*$/,"")}function s(a,b,c){for(var d=0,e=c.length;e>d;d++)if("type"===c[d].name.toLowerCase()&&b.processScripts.indexOf(c[d].value)>-1)return F(a,b);return a}function t(a,b){return a.replace(K[b],"").replace(L[b],"")}function u(a){return/^(?:html|t?body|t?head|tfoot|tr|td|th|dt|dd|option|colgroup|source)$/.test(a)}function v(a,b,c){var d=/^(["'])?\s*\1$/.test(c);return d?"input"===a&&"value"===b||M.test(b):!1}function w(a){return"textarea"!==a}function x(a){return!/^(?:script|style|pre|textarea)$/.test(a)}function y(a){return!/^(?:pre|textarea)$/.test(a)}function z(a){for(var b="",c=0,d=a.length;d>c;c++)b+=" "+a[c].name+(l(a[c].value)?"":'="'+a[c].value+'"');return b}function A(a,b,c,d){var e,f=d.caseSensitive?a.name:a.name.toLowerCase(),h=a.escaped;return d.removeRedundantAttributes&&i(c,f,h,b)||d.removeScriptTypeAttributes&&j(c,f,h)||d.removeStyleLinkTypeAttributes&&k(c,f,h)?"":(h=o(c,f,h,d,b),(void 0!==h&&!d.removeAttributeQuotes||!g(h))&&(h='"'+h+'"'),d.removeEmptyAttributes&&v(c,f,h)?"":(e=void 0===h||d.collapseBooleanAttributes&&l(f)?f:f+a.customAssign+h," "+a.customOpen+e+a.customClose))}function B(a){for(var b=["canCollapseWhitespace","canTrimWhitespace"],c=0,d=b.length;d>c;c++)a[b[c]]||(a[b[c]]=function(){return!1})}function C(b,c){"object"!=typeof c&&(c={});try{var d=a.RelateUrl;return"undefined"==typeof d&&"function"==typeof require&&(d=require("relateurl")),d&&d.relate?d.relate(b,c):b}catch(e){H(e)}return b}function D(b,c){"object"!=typeof c&&(c={}),c.fromString=!0,c.output={inline_script:!0};try{var d=a.UglifyJS;if("undefined"==typeof d&&"function"==typeof require&&(d=require("uglify-js")),!d)return b;if(d.minify)return d.minify(b,c).code;if(d.parse){var e=d.parse(b);e.figure_out_scope();var f=d.Compressor(),g=e.transform(f);g.figure_out_scope(),g.compute_char_frequency(),c.mangle!==!1&&g.mangle_names();var h=d.OutputStream(c.output);return g.print(h),h.toString()}return b}catch(i){H(i)}return b}function E(a,b){"object"!=typeof b&&(b={}),"undefined"==typeof b.noAdvanced&&(b.noAdvanced=!0);try{if("undefined"!=typeof CleanCSS)return new CleanCSS(b).minify(a);if("function"==typeof require){var c=require("clean-css");return new c(b).minify(a)}}catch(d){H(d)}return a}function F(a,f){function g(a,b){return x(a)||f.canCollapseWhitespace(a,b)}function h(a,b){return y(a)||f.canTrimWhitespace(a,b)}f=f||{},a=J(a),B(f);var i=[],j=[],k="",l="",m=[],n=[],o=[],p=f.lint,v=!1,C=new Date;new I(a,{html5:"undefined"!=typeof f.html5?f.html5:!0,start:function(a,b,c,d){if(v)return void j.push("<"+a,z(b),d?"/":"",">");a=f.caseSensitive?a:a.toLowerCase(),l=a,k="",m=b,f.collapseWhitespace&&(h(a,b)||n.push(a),g(a,b)||o.push(a));var e="<"+a,i=(d&&f.keepClosingSlash?"/":"")+">";0===b.length&&(e+=i),j.push(e),p&&p.testElement(a);for(var q,r=0,s=b.length;s>r;r++)p&&p.testAttribute(a,b[r].name.toLowerCase(),b[r].escaped),q=A(b[r],b,a,f),r===s-1&&(q+=i),j.push(q)},end:function(a){if(v)return void j.push("");f.collapseWhitespace&&(n.length&&a===n[n.length-1]&&n.pop(),o.length&&a===o[o.length-1]&&o.pop());var b=""===k&&a===l;if(f.removeEmptyElements&&b&&w(a)){for(var c=j.length-1;c>=0;c--)if(/^<[^\/!]/.test(j[c])){j.splice(c);break}}else f.removeOptionalTags&&u(a)||(j.push(""),i.push.apply(i,j),j.length=0,k="")},chars:function(a,d,e){return v?void j.push(a):(("script"===l||"style"===l)&&(f.removeCommentsFromCDATA&&(a=t(a,l)),f.removeCDATASectionsFromCDATA&&(a=r(a)),f.processScripts&&(a=s(a,f,m))),"script"===l&&f.minifyJS&&(a=D(a,f.minifyJS)),"style"===l&&f.minifyCSS&&(a=E(a,f.minifyCSS)),f.collapseWhitespace&&(n.length||(a=d||e?c(a,d,e,f):J(a)),o.length||(a=b(a))),k=a,p&&p.testChars(a),void j.push(a))},comment:function(a,b){var c=b?"":"-->";return/^\s*htmlmin:ignore/.test(a)?(v=!v,void j.push("")):(a=f.removeComments?d(a)?c+q(a)+g:e(a,f)?"":"":c+a+g,void j.push(a))},ignore:function(a){j.push(f.removeIgnored?"":a)},doctype:function(a){j.push(f.useShortDoctype?"":b(a))},customAttrAssign:f.customAttrAssign,customAttrSurround:f.customAttrSurround}),i.push.apply(i,j);var F=G(i,f);return H("minified in: "+(new Date-C)+"ms"),F}function G(a,b){var c,d=b.maxLineLength;if(d){for(var e,f=[],g="",h=0,i=a.length;i>h;h++)e=a[h],g.length+e.length\s*$/,style:/\s*-->\s*$/},M=new RegExp("^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(?:down|up|over|move|out)|key(?:press|down|up)))$");"undefined"!=typeof exports?exports.minify=F:a.minify=F}(this),function(a){"use strict";function b(a){return/^(?:big|small|hr|blink|marquee)$/.test(a)}function c(a){return/^(?:applet|basefont|center|dir|font|isindex|strike)$/.test(a)}function d(a){return/^on[a-z]+/.test(a)}function e(a){return"style"===a.toLowerCase()}function f(a,b){return"align"===b&&/^(?:caption|applet|iframe|img|imput|object|legend|table|hr|div|h[1-6]|p)$/.test(a)||"alink"===b&&"body"===a||"alt"===b&&"applet"===a||"archive"===b&&"applet"===a||"background"===b&&"body"===a||"bgcolor"===b&&/^(?:table|t[rdh]|body)$/.test(a)||"border"===b&&/^(?:img|object)$/.test(a)||"clear"===b&&"br"===a||"code"===b&&"applet"===a||"codebase"===b&&"applet"===a||"color"===b&&/^(?:base(?:font)?)$/.test(a)||"compact"===b&&/^(?:dir|[dou]l|menu)$/.test(a)||"face"===b&&/^base(?:font)?$/.test(a)||"height"===b&&/^(?:t[dh]|applet)$/.test(a)||"hspace"===b&&/^(?:applet|img|object)$/.test(a)||"language"===b&&"script"===a||"link"===b&&"body"===a||"name"===b&&"applet"===a||"noshade"===b&&"hr"===a||"nowrap"===b&&/^t[dh]$/.test(a)||"object"===b&&"applet"===a||"prompt"===b&&"isindex"===a||"size"===b&&/^(?:hr|font|basefont)$/.test(a)||"start"===b&&"ol"===a||"text"===b&&"body"===a||"type"===b&&/^(?:li|ol|ul)$/.test(a)||"value"===b&&"li"===a||"version"===b&&"html"===a||"vlink"===b&&"body"===a||"vspace"===b&&/^(?:applet|img|object)$/.test(a)||"width"===b&&/^(?:hr|td|th|applet|pre)$/.test(a)}function g(a,b){return"href"===a&&/^\s*javascript\s*:\s*void\s*(\s+0|\(\s*0\s*\))\s*$/i.test(b)}function h(){this.log=[],this._lastElement=null,this._isElementRepeated=!1}h.prototype.testElement=function(a){c(a)?this.log.push('Found deprecated <'+a+"> element"):b(a)?this.log.push('Found presentational <'+a+"> element"):this.checkRepeatingElement(a)},h.prototype.checkRepeatingElement=function(a){"br"===a&&"br"===this._lastElement?this._isElementRepeated=!0:this._isElementRepeated&&(this._reportRepeatingElement(),this._isElementRepeated=!1),this._lastElement=a},h.prototype._reportRepeatingElement=function(){this.log.push("Found <br> sequence. Try replacing it with styling.")},h.prototype.testAttribute=function(a,b,c){d(b)?this.log.push('Found event attribute ('+b+") on <"+a+"> element."):f(a,b)?this.log.push('Found deprecated '+b+" attribute on <"+a+"> element."):e(b)?this.log.push('Found style attribute on <'+a+"> element."):g(b,c)&&this.log.push('Found inaccessible attribute (on <'+a+"> element).")},h.prototype.testChars=function(a){this._lastElement="",/( \s*){2,}/.test(a)&&this.log.push("Found repeating &nbsp; sequence. Try replacing it with styling.")},h.prototype.test=function(a,b,c){this.testElement(a),this.testAttribute(a,b,c)},h.prototype.populate=function(a){if(this._isElementRepeated&&this._reportRepeatingElement(),this.log.length)if(a)a.innerHTML="
  1. "+this.log.join("
  2. ")+"
";else{var b=" - "+this.log.join("\n - ").replace(/(<([^>]+)>)/gi,"").replace(/</g,"<").replace(/>/g,">");console.log(b)}},a.HTMLLint=h}("undefined"==typeof exports?this:exports); \ No newline at end of file diff --git a/index.html b/index.html index fbeee0e..182289d 100644 --- a/index.html +++ b/index.html @@ -210,6 +210,22 @@ Minify CSS +
  • + + +
  • +
  • + + +