>>=y,p-=y),p<15&&(d+=z[n++]<>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<>>=y,p-=y,(y=s-a)>3,d&=(1<<(p-=w<<3))-1,e.next_in=n,e.next_out=s,e.avail_in=n>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24)}function s(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new I.Buf16(320),this.work=new I.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function a(e){var t;return e&&e.state?(t=e.state,e.total_in=e.total_out=t.total=0,e.msg=\"\",t.wrap&&(e.adler=1&t.wrap),t.mode=P,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new I.Buf32(n),t.distcode=t.distdyn=new I.Buf32(i),t.sane=1,t.back=-1,N):U}function o(e){var t;return e&&e.state?((t=e.state).wsize=0,t.whave=0,t.wnext=0,a(e)):U}function h(e,t){var r,n;return e&&e.state?(n=e.state,t<0?(r=0,t=-t):(r=1+(t>>4),t<48&&(t&=15)),t&&(t<8||15=s.wsize?(I.arraySet(s.window,t,r-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(n<(i=s.wsize-s.wnext)&&(i=n),I.arraySet(s.window,t,r-n,i,s.wnext),(n-=i)?(I.arraySet(s.window,t,r-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,r.check=B(r.check,E,2,0),l=u=0,r.mode=2;break}if(r.flags=0,r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&u)<<8)+(u>>8))%31){e.msg=\"incorrect header check\",r.mode=30;break}if(8!=(15&u)){e.msg=\"unknown compression method\",r.mode=30;break}if(l-=4,k=8+(15&(u>>>=4)),0===r.wbits)r.wbits=k;else if(k>r.wbits){e.msg=\"invalid window size\",r.mode=30;break}r.dmax=1<>8&1),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=3;case 3:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>8&255,E[2]=u>>>16&255,E[3]=u>>>24&255,r.check=B(r.check,E,4,0)),l=u=0,r.mode=4;case 4:for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>8),512&r.flags&&(E[0]=255&u,E[1]=u>>>8&255,r.check=B(r.check,E,2,0)),l=u=0,r.mode=5;case 5:if(1024&r.flags){for(;l<16;){if(0===o)break e;o--,u+=n[s++]<>>8&255,r.check=B(r.check,E,2,0)),l=u=0}else r.head&&(r.head.extra=null);r.mode=6;case 6:if(1024&r.flags&&(o<(d=r.length)&&(d=o),d&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),I.arraySet(r.head.extra,n,s,d,k)),512&r.flags&&(r.check=B(r.check,n,d,s)),o-=d,s+=d,r.length-=d),r.length))break e;r.length=0,r.mode=7;case 7:if(2048&r.flags){if(0===o)break e;for(d=0;k=n[s+d++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k)),k&&d>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=12;break;case 10:for(;l<32;){if(0===o)break e;o--,u+=n[s++]<>>=7&l,l-=7&l,r.mode=27;break}for(;l<3;){if(0===o)break e;o--,u+=n[s++]<>>=1)){case 0:r.mode=14;break;case 1:if(j(r),r.mode=20,6!==t)break;u>>>=2,l-=2;break e;case 2:r.mode=17;break;case 3:e.msg=\"invalid block type\",r.mode=30}u>>>=2,l-=2;break;case 14:for(u>>>=7&l,l-=7&l;l<32;){if(0===o)break e;o--,u+=n[s++]<>>16^65535)){e.msg=\"invalid stored block lengths\",r.mode=30;break}if(r.length=65535&u,l=u=0,r.mode=15,6===t)break e;case 15:r.mode=16;case 16:if(d=r.length){if(o>>=5,l-=5,r.ndist=1+(31&u),u>>>=5,l-=5,r.ncode=4+(15&u),u>>>=4,l-=4,286>>=3,l-=3}for(;r.have<19;)r.lens[A[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,S={bits:r.lenbits},x=T(0,r.lens,0,19,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg=\"invalid code lengths set\",r.mode=30;break}r.have=0,r.mode=19;case 19:for(;r.have>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=_,l-=_,r.lens[r.have++]=b;else{if(16===b){for(z=_+2;l>>=_,l-=_,0===r.have){e.msg=\"invalid bit length repeat\",r.mode=30;break}k=r.lens[r.have-1],d=3+(3&u),u>>>=2,l-=2}else if(17===b){for(z=_+3;l>>=_)),u>>>=3,l-=3}else{for(z=_+7;l>>=_)),u>>>=7,l-=7}if(r.have+d>r.nlen+r.ndist){e.msg=\"invalid bit length repeat\",r.mode=30;break}for(;d--;)r.lens[r.have++]=k}}if(30===r.mode)break;if(0===r.lens[256]){e.msg=\"invalid code -- missing end-of-block\",r.mode=30;break}if(r.lenbits=9,S={bits:r.lenbits},x=T(D,r.lens,0,r.nlen,r.lencode,0,r.work,S),r.lenbits=S.bits,x){e.msg=\"invalid literal/lengths set\",r.mode=30;break}if(r.distbits=6,r.distcode=r.distdyn,S={bits:r.distbits},x=T(F,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,S),r.distbits=S.bits,x){e.msg=\"invalid distances set\",r.mode=30;break}if(r.mode=20,6===t)break e;case 20:r.mode=21;case 21:if(6<=o&&258<=h){e.next_out=a,e.avail_out=h,e.next_in=s,e.avail_in=o,r.hold=u,r.bits=l,R(e,c),a=e.next_out,i=e.output,h=e.avail_out,s=e.next_in,n=e.input,o=e.avail_in,u=r.hold,l=r.bits,12===r.mode&&(r.back=-1);break}for(r.back=0;g=(C=r.lencode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,r.length=b,0===g){r.mode=26;break}if(32&g){r.back=-1,r.mode=12;break}if(64&g){e.msg=\"invalid literal/length code\",r.mode=30;break}r.extra=15&g,r.mode=22;case 22:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=23;case 23:for(;g=(C=r.distcode[u&(1<>>16&255,b=65535&C,!((_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>v)])>>>16&255,b=65535&C,!(v+(_=C>>>24)<=l);){if(0===o)break e;o--,u+=n[s++]<>>=v,l-=v,r.back+=v}if(u>>>=_,l-=_,r.back+=_,64&g){e.msg=\"invalid distance code\",r.mode=30;break}r.offset=b,r.extra=15&g,r.mode=24;case 24:if(r.extra){for(z=r.extra;l>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg=\"invalid distance too far back\",r.mode=30;break}r.mode=25;case 25:if(0===h)break e;if(d=c-h,r.offset>d){if((d=r.offset-d)>r.whave&&r.sane){e.msg=\"invalid distance too far back\",r.mode=30;break}p=d>r.wnext?(d-=r.wnext,r.wsize-d):r.wnext-d,d>r.length&&(d=r.length),m=r.window}else m=i,p=a-r.offset,d=r.length;for(hd?(m=R[T+a[v]],A[I+a[v]]):(m=96,0),h=1<>S)+(u-=h)]=p<<24|m<<16|_|0,0!==u;);for(h=1<>=1;if(0!==h?(E&=h-1,E+=h):E=0,v++,0==--O[b]){if(b===w)break;b=t[r+a[v]]}if(k>>7)]}function U(e,t){e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255}function P(e,t,r){e.bi_valid>d-r?(e.bi_buf|=t<>d-e.bi_valid,e.bi_valid+=r-d):(e.bi_buf|=t<>>=1,r<<=1,0<--t;);return r>>>1}function Z(e,t,r){var n,i,s=new Array(g+1),a=0;for(n=1;n<=g;n++)s[n]=a=a+r[n-1]<<1;for(i=0;i<=t;i++){var o=e[2*i+1];0!==o&&(e[2*i]=j(s[o]++,o))}}function W(e){var t;for(t=0;t>1;1<=r;r--)G(e,s,r);for(i=h;r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],G(e,s,1),n=e.heap[1],e.heap[--e.heap_max]=r,e.heap[--e.heap_max]=n,s[2*i]=s[2*r]+s[2*n],e.depth[i]=(e.depth[r]>=e.depth[n]?e.depth[r]:e.depth[n])+1,s[2*r+1]=s[2*n+1]=i,e.heap[1]=i++,G(e,s,1),2<=e.heap_len;);e.heap[--e.heap_max]=e.heap[1],function(e,t){var r,n,i,s,a,o,h=t.dyn_tree,u=t.max_code,l=t.stat_desc.static_tree,f=t.stat_desc.has_stree,c=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,p=t.stat_desc.max_length,m=0;for(s=0;s<=g;s++)e.bl_count[s]=0;for(h[2*e.heap[e.heap_max]+1]=0,r=e.heap_max+1;r<_;r++)p<(s=h[2*h[2*(n=e.heap[r])+1]+1]+1)&&(s=p,m++),h[2*n+1]=s,u>=7;n>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return o;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return h;for(t=32;t>>3,(s=e.static_len+3+7>>>3)<=i&&(i=s)):i=s=r+5,r+4<=i&&-1!==t?J(e,t,r,n):4===e.strategy||s===i?(P(e,2+(n?1:0),3),K(e,z,C)):(P(e,4+(n?1:0),3),function(e,t,r,n){var i;for(P(e,t-257,5),P(e,r-1,5),P(e,n-4,4),i=0;i>>8&255,e.pending_buf[e.d_buf+2*e.last_lit+1]=255&t,e.pending_buf[e.l_buf+e.last_lit]=255&r,e.last_lit++,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(A[r]+u+1)]++,e.dyn_dtree[2*N(t)]++),e.last_lit===e.lit_bufsize-1},r._tr_align=function(e){P(e,2,3),L(e,m,z),function(e){16===e.bi_valid?(U(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):8<=e.bi_valid&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)}(e)}},{\"../utils/common\":41}],53:[function(e,t,r){\"use strict\";t.exports=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg=\"\",this.state=null,this.data_type=2,this.adler=0}},{}],54:[function(e,t,r){(function(e){!function(r,n){\"use strict\";if(!r.setImmediate){var i,s,t,a,o=1,h={},u=!1,l=r.document,e=Object.getPrototypeOf&&Object.getPrototypeOf(r);e=e&&e.setTimeout?e:r,i=\"[object process]\"==={}.toString.call(r.process)?function(e){process.nextTick(function(){c(e)})}:function(){if(r.postMessage&&!r.importScripts){var e=!0,t=r.onmessage;return r.onmessage=function(){e=!1},r.postMessage(\"\",\"*\"),r.onmessage=t,e}}()?(a=\"setImmediate$\"+Math.random()+\"$\",r.addEventListener?r.addEventListener(\"message\",d,!1):r.attachEvent(\"onmessage\",d),function(e){r.postMessage(a+e,\"*\")}):r.MessageChannel?((t=new MessageChannel).port1.onmessage=function(e){c(e.data)},function(e){t.port2.postMessage(e)}):l&&\"onreadystatechange\"in l.createElement(\"script\")?(s=l.documentElement,function(e){var t=l.createElement(\"script\");t.onreadystatechange=function(){c(e),t.onreadystatechange=null,s.removeChild(t),t=null},s.appendChild(t)}):function(e){setTimeout(c,0,e)},e.setImmediate=function(e){\"function\"!=typeof e&&(e=new Function(\"\"+e));for(var t=new Array(arguments.length-1),r=0;r this._canPossiblyFulfill()) {\n this._reject(this._getRangeError(this.length()));\n }\n};\n\nSomePromiseArray.prototype.init = function () {\n this._initialized = true;\n this._init();\n};\n\nSomePromiseArray.prototype.setUnwrap = function () {\n this._unwrap = true;\n};\n\nSomePromiseArray.prototype.howMany = function () {\n return this._howMany;\n};\n\nSomePromiseArray.prototype.setHowMany = function (count) {\n this._howMany = count;\n};\n\nSomePromiseArray.prototype._promiseFulfilled = function (value) {\n this._addFulfilled(value);\n if (this._fulfilled() === this.howMany()) {\n this._values.length = this.howMany();\n if (this.howMany() === 1 && this._unwrap) {\n this._resolve(this._values[0]);\n } else {\n this._resolve(this._values);\n }\n return true;\n }\n return false;\n\n};\nSomePromiseArray.prototype._promiseRejected = function (reason) {\n this._addRejected(reason);\n return this._checkOutcome();\n};\n\nSomePromiseArray.prototype._promiseCancelled = function () {\n if (this._values instanceof Promise || this._values == null) {\n return this._cancel();\n }\n this._addRejected(CANCELLATION);\n return this._checkOutcome();\n};\n\nSomePromiseArray.prototype._checkOutcome = function() {\n if (this.howMany() > this._canPossiblyFulfill()) {\n var e = new AggregateError();\n for (var i = this.length(); i < this._values.length; ++i) {\n if (this._values[i] !== CANCELLATION) {\n e.push(this._values[i]);\n }\n }\n if (e.length > 0) {\n this._reject(e);\n } else {\n this._cancel();\n }\n return true;\n }\n return false;\n};\n\nSomePromiseArray.prototype._fulfilled = function () {\n return this._totalResolved;\n};\n\nSomePromiseArray.prototype._rejected = function () {\n return this._values.length - this.length();\n};\n\nSomePromiseArray.prototype._addRejected = function (reason) {\n this._values.push(reason);\n};\n\nSomePromiseArray.prototype._addFulfilled = function (value) {\n this._values[this._totalResolved++] = value;\n};\n\nSomePromiseArray.prototype._canPossiblyFulfill = function () {\n return this.length() - this._rejected();\n};\n\nSomePromiseArray.prototype._getRangeError = function (count) {\n var message = \"Input array must contain at least \" +\n this._howMany + \" items but contains only \" + count + \" items\";\n return new RangeError(message);\n};\n\nSomePromiseArray.prototype._resolveEmptyArray = function () {\n this._reject(this._getRangeError(0));\n};\n\nfunction some(promises, howMany) {\n if ((howMany | 0) !== howMany || howMany < 0) {\n return apiRejection(\"expecting a positive integer\\u000a\\u000a See http://goo.gl/MqrFmX\\u000a\");\n }\n var ret = new SomePromiseArray(promises);\n var promise = ret.promise();\n ret.setHowMany(howMany);\n ret.init();\n return promise;\n}\n\nPromise.some = function (promises, howMany) {\n return some(promises, howMany);\n};\n\nPromise.prototype.some = function (howMany) {\n return some(this, howMany);\n};\n\nPromise._SomePromiseArray = SomePromiseArray;\n};\n","\"use strict\";\nmodule.exports =\nfunction(Promise, PromiseArray, tryConvertToPromise, INTERNAL, async,\n getDomain) {\nvar util = require(\"./util\");\nvar canEvaluate = util.canEvaluate;\nvar tryCatch = util.tryCatch;\nvar errorObj = util.errorObj;\nvar reject;\n\nif (!false) {\nif (canEvaluate) {\n var thenCallback = function(i) {\n return new Function(\"value\", \"holder\", \" \\n\\\n 'use strict'; \\n\\\n holder.pIndex = value; \\n\\\n holder.checkFulfillment(this); \\n\\\n \".replace(/Index/g, i));\n };\n\n var promiseSetter = function(i) {\n return new Function(\"promise\", \"holder\", \" \\n\\\n 'use strict'; \\n\\\n holder.pIndex = promise; \\n\\\n \".replace(/Index/g, i));\n };\n\n var generateHolderClass = function(total) {\n var props = new Array(total);\n for (var i = 0; i < props.length; ++i) {\n props[i] = \"this.p\" + (i+1);\n }\n var assignment = props.join(\" = \") + \" = null;\";\n var cancellationCode= \"var promise;\\n\" + props.map(function(prop) {\n return \" \\n\\\n promise = \" + prop + \"; \\n\\\n if (promise instanceof Promise) { \\n\\\n promise.cancel(); \\n\\\n } \\n\\\n \";\n }).join(\"\\n\");\n var passedArguments = props.join(\", \");\n var name = \"Holder$\" + total;\n\n\n var code = \"return function(tryCatch, errorObj, Promise, async) { \\n\\\n 'use strict'; \\n\\\n function [TheName](fn) { \\n\\\n [TheProperties] \\n\\\n this.fn = fn; \\n\\\n this.asyncNeeded = true; \\n\\\n this.now = 0; \\n\\\n } \\n\\\n \\n\\\n [TheName].prototype._callFunction = function(promise) { \\n\\\n promise._pushContext(); \\n\\\n var ret = tryCatch(this.fn)([ThePassedArguments]); \\n\\\n promise._popContext(); \\n\\\n if (ret === errorObj) { \\n\\\n promise._rejectCallback(ret.e, false); \\n\\\n } else { \\n\\\n promise._resolveCallback(ret); \\n\\\n } \\n\\\n }; \\n\\\n \\n\\\n [TheName].prototype.checkFulfillment = function(promise) { \\n\\\n var now = ++this.now; \\n\\\n if (now === [TheTotal]) { \\n\\\n if (this.asyncNeeded) { \\n\\\n async.invoke(this._callFunction, this, promise); \\n\\\n } else { \\n\\\n this._callFunction(promise); \\n\\\n } \\n\\\n \\n\\\n } \\n\\\n }; \\n\\\n \\n\\\n [TheName].prototype._resultCancelled = function() { \\n\\\n [CancellationCode] \\n\\\n }; \\n\\\n \\n\\\n return [TheName]; \\n\\\n }(tryCatch, errorObj, Promise, async); \\n\\\n \";\n\n code = code.replace(/\\[TheName\\]/g, name)\n .replace(/\\[TheTotal\\]/g, total)\n .replace(/\\[ThePassedArguments\\]/g, passedArguments)\n .replace(/\\[TheProperties\\]/g, assignment)\n .replace(/\\[CancellationCode\\]/g, cancellationCode);\n\n return new Function(\"tryCatch\", \"errorObj\", \"Promise\", \"async\", code)\n (tryCatch, errorObj, Promise, async);\n };\n\n var holderClasses = [];\n var thenCallbacks = [];\n var promiseSetters = [];\n\n for (var i = 0; i < 8; ++i) {\n holderClasses.push(generateHolderClass(i + 1));\n thenCallbacks.push(thenCallback(i + 1));\n promiseSetters.push(promiseSetter(i + 1));\n }\n\n reject = function (reason) {\n this._reject(reason);\n };\n}}\n\nPromise.join = function () {\n var last = arguments.length - 1;\n var fn;\n if (last > 0 && typeof arguments[last] === \"function\") {\n fn = arguments[last];\n if (!false) {\n if (last <= 8 && canEvaluate) {\n var ret = new Promise(INTERNAL);\n ret._captureStackTrace();\n var HolderClass = holderClasses[last - 1];\n var holder = new HolderClass(fn);\n var callbacks = thenCallbacks;\n\n for (var i = 0; i < last; ++i) {\n var maybePromise = tryConvertToPromise(arguments[i], ret);\n if (maybePromise instanceof Promise) {\n maybePromise = maybePromise._target();\n var bitField = maybePromise._bitField;\n ;\n if (((bitField & 50397184) === 0)) {\n maybePromise._then(callbacks[i], reject,\n undefined, ret, holder);\n promiseSetters[i](maybePromise, holder);\n holder.asyncNeeded = false;\n } else if (((bitField & 33554432) !== 0)) {\n callbacks[i].call(ret,\n maybePromise._value(), holder);\n } else if (((bitField & 16777216) !== 0)) {\n ret._reject(maybePromise._reason());\n } else {\n ret._cancel();\n }\n } else {\n callbacks[i].call(ret, maybePromise, holder);\n }\n }\n\n if (!ret._isFateSealed()) {\n if (holder.asyncNeeded) {\n var domain = getDomain();\n if (domain !== null) {\n holder.fn = util.domainBind(domain, holder.fn);\n }\n }\n ret._setAsyncGuaranteed();\n ret._setOnCancel(holder);\n }\n return ret;\n }\n }\n }\n var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];};\n if (fn) args.pop();\n var ret = new PromiseArray(args).promise();\n return fn !== undefined ? ret.spread(fn) : ret;\n};\n\n};\n","module.exports = function isBuffer(arg) {\n return arg && typeof arg === 'object'\n && typeof arg.copy === 'function'\n && typeof arg.fill === 'function'\n && typeof arg.readUInt8 === 'function';\n}","var _ = require(\"underscore\");\n\n\nfunction symmetricMarkdownElement(end) {\n return markdownElement(end, end);\n}\n\nfunction markdownElement(start, end) {\n return function() {\n return {start: start, end: end};\n };\n}\n\nfunction markdownLink(attributes) {\n var href = attributes.href || \"\";\n if (href) {\n return {\n start: \"[\",\n end: \"](\" + href + \")\",\n anchorPosition: \"before\"\n };\n } else {\n return {};\n }\n}\n\nfunction markdownImage(attributes) {\n var src = attributes.src || \"\";\n var altText = attributes.alt || \"\";\n if (src || altText) {\n return {start: \"\"};\n } else {\n return {};\n }\n}\n\nfunction markdownList(options) {\n return function(attributes, list) {\n return {\n start: list ? \"\\n\" : \"\",\n end: list ? \"\" : \"\\n\",\n list: {\n isOrdered: options.isOrdered,\n indent: list ? list.indent + 1 : 0,\n count: 0\n }\n };\n };\n}\n\nfunction markdownListItem(attributes, list, listItem) {\n list = list || {indent: 0, isOrdered: false, count: 0};\n list.count++;\n listItem.hasClosed = false;\n \n var bullet = list.isOrdered ? list.count + \".\" : \"-\";\n var start = repeatString(\"\\t\", list.indent) + bullet + \" \";\n \n return {\n start: start,\n end: function() {\n if (!listItem.hasClosed) {\n listItem.hasClosed = true;\n return \"\\n\";\n }\n }\n };\n}\n\nvar htmlToMarkdown = {\n \"p\": markdownElement(\"\", \"\\n\\n\"),\n \"br\": markdownElement(\"\", \" \\n\"),\n \"ul\": markdownList({isOrdered: false}),\n \"ol\": markdownList({isOrdered: true}),\n \"li\": markdownListItem,\n \"strong\": symmetricMarkdownElement(\"__\"),\n \"em\": symmetricMarkdownElement(\"*\"),\n \"a\": markdownLink,\n \"img\": markdownImage\n};\n\n(function() {\n for (var i = 1; i <= 6; i++) {\n htmlToMarkdown[\"h\" + i] = markdownElement(repeatString(\"#\", i) + \" \", \"\\n\\n\");\n }\n})();\n\nfunction repeatString(value, count) {\n return new Array(count + 1).join(value);\n}\n\nfunction markdownWriter() {\n var fragments = [];\n var elementStack = [];\n var list = null;\n var listItem = {};\n \n function open(tagName, attributes) {\n attributes = attributes || {};\n \n var createElement = htmlToMarkdown[tagName] || function() {\n return {};\n };\n var element = createElement(attributes, list, listItem);\n elementStack.push({end: element.end, list: list});\n \n if (element.list) {\n list = element.list;\n }\n \n var anchorBeforeStart = element.anchorPosition === \"before\";\n if (anchorBeforeStart) {\n writeAnchor(attributes);\n }\n\n fragments.push(element.start || \"\");\n if (!anchorBeforeStart) {\n writeAnchor(attributes);\n }\n }\n \n function writeAnchor(attributes) {\n if (attributes.id) {\n fragments.push('');\n }\n }\n \n function close(tagName) {\n var element = elementStack.pop();\n list = element.list;\n var end = _.isFunction(element.end) ? element.end() : element.end;\n fragments.push(end || \"\");\n }\n \n function selfClosing(tagName, attributes) {\n open(tagName, attributes);\n close(tagName);\n }\n \n function text(value) {\n fragments.push(escapeMarkdown(value));\n }\n \n function asString() {\n return fragments.join(\"\");\n }\n\n return {\n asString: asString,\n open: open,\n close: close,\n text: text,\n selfClosing: selfClosing\n };\n}\n\nexports.writer = markdownWriter;\n\nfunction escapeMarkdown(value) {\n return value\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/([\\`\\*_\\{\\}\\[\\]\\(\\)\\#\\+\\-\\.\\!])/g, '\\\\$1');\n}\n","var _ = require(\"underscore\");\n\n\nexports.Element = Element;\nexports.element = function(name, attributes, children) {\n return new Element(name, attributes, children);\n};\nexports.text = function(value) {\n return {\n type: \"text\",\n value: value\n };\n};\n\n\nvar emptyElement = {\n first: function() {\n return null;\n },\n firstOrEmpty: function() {\n return emptyElement;\n },\n attributes: {}\n};\n\nfunction Element(name, attributes, children) {\n this.type = \"element\";\n this.name = name;\n this.attributes = attributes || {};\n this.children = children || [];\n}\n\nElement.prototype.first = function(name) {\n return _.find(this.children, function(child) {\n return child.name === name;\n });\n};\n\nElement.prototype.firstOrEmpty = function(name) {\n return this.first(name) || emptyElement;\n};\n\nElement.prototype.getElementsByTagName = function(name) {\n var elements = _.filter(this.children, function(child) {\n return child.name === name;\n });\n return toElementList(elements);\n};\n\nElement.prototype.text = function() {\n if (this.children.length === 0) {\n return \"\";\n } else if (this.children.length !== 1 || this.children[0].type !== \"text\") {\n throw new Error(\"Not implemented\");\n }\n return this.children[0].value;\n};\n\nvar elementListPrototype = {\n getElementsByTagName: function(name) {\n return toElementList(_.flatten(this.map(function(element) {\n return element.getElementsByTagName(name);\n }, true)));\n }\n};\n\nfunction toElementList(array) {\n return _.extend(array, elementListPrototype);\n}\n","\"use strict\";\nmodule.exports = function(Promise) {\nvar SomePromiseArray = Promise._SomePromiseArray;\nfunction any(promises) {\n var ret = new SomePromiseArray(promises);\n var promise = ret.promise();\n ret.setHowMany(1);\n ret.setUnwrap();\n ret.init();\n return promise;\n}\n\nPromise.any = function (promises) {\n return any(promises);\n};\n\nPromise.prototype.any = function () {\n return any(this);\n};\n\n};\n","// Generated by CoffeeScript 1.12.7\n(function() {\n var XMLDTDAttList, XMLDTDElement, XMLDTDEntity, XMLDTDNotation, XMLDocType, XMLNode, isObject,\n extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },\n hasProp = {}.hasOwnProperty;\n\n isObject = require('./Utility').isObject;\n\n XMLNode = require('./XMLNode');\n\n XMLDTDAttList = require('./XMLDTDAttList');\n\n XMLDTDEntity = require('./XMLDTDEntity');\n\n XMLDTDElement = require('./XMLDTDElement');\n\n XMLDTDNotation = require('./XMLDTDNotation');\n\n module.exports = XMLDocType = (function(superClass) {\n extend(XMLDocType, superClass);\n\n function XMLDocType(parent, pubID, sysID) {\n var ref, ref1;\n XMLDocType.__super__.constructor.call(this, parent);\n this.name = \"!DOCTYPE\";\n this.documentObject = parent;\n if (isObject(pubID)) {\n ref = pubID, pubID = ref.pubID, sysID = ref.sysID;\n }\n if (sysID == null) {\n ref1 = [pubID, sysID], sysID = ref1[0], pubID = ref1[1];\n }\n if (pubID != null) {\n this.pubID = this.stringify.dtdPubID(pubID);\n }\n if (sysID != null) {\n this.sysID = this.stringify.dtdSysID(sysID);\n }\n }\n\n XMLDocType.prototype.element = function(name, value) {\n var child;\n child = new XMLDTDElement(this, name, value);\n this.children.push(child);\n return this;\n };\n\n XMLDocType.prototype.attList = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {\n var child;\n child = new XMLDTDAttList(this, elementName, attributeName, attributeType, defaultValueType, defaultValue);\n this.children.push(child);\n return this;\n };\n\n XMLDocType.prototype.entity = function(name, value) {\n var child;\n child = new XMLDTDEntity(this, false, name, value);\n this.children.push(child);\n return this;\n };\n\n XMLDocType.prototype.pEntity = function(name, value) {\n var child;\n child = new XMLDTDEntity(this, true, name, value);\n this.children.push(child);\n return this;\n };\n\n XMLDocType.prototype.notation = function(name, value) {\n var child;\n child = new XMLDTDNotation(this, name, value);\n this.children.push(child);\n return this;\n };\n\n XMLDocType.prototype.toString = function(options) {\n return this.options.writer.set(options).docType(this);\n };\n\n XMLDocType.prototype.ele = function(name, value) {\n return this.element(name, value);\n };\n\n XMLDocType.prototype.att = function(elementName, attributeName, attributeType, defaultValueType, defaultValue) {\n return this.attList(elementName, attributeName, attributeType, defaultValueType, defaultValue);\n };\n\n XMLDocType.prototype.ent = function(name, value) {\n return this.entity(name, value);\n };\n\n XMLDocType.prototype.pent = function(name, value) {\n return this.pEntity(name, value);\n };\n\n XMLDocType.prototype.not = function(name, value) {\n return this.notation(name, value);\n };\n\n XMLDocType.prototype.up = function() {\n return this.root() || this.documentObject;\n };\n\n return XMLDocType;\n\n })(XMLNode);\n\n}).call(this);\n","\"use strict\";\nmodule.exports = function(\n Promise, PromiseArray, tryConvertToPromise, apiRejection) {\nvar util = require(\"./util\");\nvar isObject = util.isObject;\nvar es5 = require(\"./es5\");\nvar Es6Map;\nif (typeof Map === \"function\") Es6Map = Map;\n\nvar mapToEntries = (function() {\n var index = 0;\n var size = 0;\n\n function extractEntry(value, key) {\n this[index] = value;\n this[index + size] = key;\n index++;\n }\n\n return function mapToEntries(map) {\n size = map.size;\n index = 0;\n var ret = new Array(map.size * 2);\n map.forEach(extractEntry, ret);\n return ret;\n };\n})();\n\nvar entriesToMap = function(entries) {\n var ret = new Es6Map();\n var length = entries.length / 2 | 0;\n for (var i = 0; i < length; ++i) {\n var key = entries[length + i];\n var value = entries[i];\n ret.set(key, value);\n }\n return ret;\n};\n\nfunction PropertiesPromiseArray(obj) {\n var isMap = false;\n var entries;\n if (Es6Map !== undefined && obj instanceof Es6Map) {\n entries = mapToEntries(obj);\n isMap = true;\n } else {\n var keys = es5.keys(obj);\n var len = keys.length;\n entries = new Array(len * 2);\n for (var i = 0; i < len; ++i) {\n var key = keys[i];\n entries[i] = obj[key];\n entries[i + len] = key;\n }\n }\n this.constructor$(entries);\n this._isMap = isMap;\n this._init$(undefined, -3);\n}\nutil.inherits(PropertiesPromiseArray, PromiseArray);\n\nPropertiesPromiseArray.prototype._init = function () {};\n\nPropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {\n this._values[index] = value;\n var totalResolved = ++this._totalResolved;\n if (totalResolved >= this._length) {\n var val;\n if (this._isMap) {\n val = entriesToMap(this._values);\n } else {\n val = {};\n var keyOffset = this.length();\n for (var i = 0, len = this.length(); i < len; ++i) {\n val[this._values[i + keyOffset]] = this._values[i];\n }\n }\n this._resolve(val);\n return true;\n }\n return false;\n};\n\nPropertiesPromiseArray.prototype.shouldCopyValues = function () {\n return false;\n};\n\nPropertiesPromiseArray.prototype.getActualLength = function (len) {\n return len >> 1;\n};\n\nfunction props(promises) {\n var ret;\n var castValue = tryConvertToPromise(promises);\n\n if (!isObject(castValue)) {\n return apiRejection(\"cannot await properties of a non-object\\u000a\\u000a See http://goo.gl/MqrFmX\\u000a\");\n } else if (castValue instanceof Promise) {\n ret = castValue._then(\n Promise.props, undefined, undefined, undefined, undefined);\n } else {\n ret = new PropertiesPromiseArray(castValue).promise();\n }\n\n if (castValue instanceof Promise) {\n ret._propagateFrom(castValue, 2);\n }\n return ret;\n}\n\nPromise.prototype.props = function () {\n return props(this);\n};\n\nPromise.props = function (promises) {\n return props(promises);\n};\n};\n","\"use strict\";\nmodule.exports = function (Promise, apiRejection, tryConvertToPromise,\n createContext, INTERNAL, debug) {\n var util = require(\"./util\");\n var TypeError = require(\"./errors\").TypeError;\n var inherits = require(\"./util\").inherits;\n var errorObj = util.errorObj;\n var tryCatch = util.tryCatch;\n var NULL = {};\n\n function thrower(e) {\n setTimeout(function(){throw e;}, 0);\n }\n\n function castPreservingDisposable(thenable) {\n var maybePromise = tryConvertToPromise(thenable);\n if (maybePromise !== thenable &&\n typeof thenable._isDisposable === \"function\" &&\n typeof thenable._getDisposer === \"function\" &&\n thenable._isDisposable()) {\n maybePromise._setDisposable(thenable._getDisposer());\n }\n return maybePromise;\n }\n function dispose(resources, inspection) {\n var i = 0;\n var len = resources.length;\n var ret = new Promise(INTERNAL);\n function iterator() {\n if (i >= len) return ret._fulfill();\n var maybePromise = castPreservingDisposable(resources[i++]);\n if (maybePromise instanceof Promise &&\n maybePromise._isDisposable()) {\n try {\n maybePromise = tryConvertToPromise(\n maybePromise._getDisposer().tryDispose(inspection),\n resources.promise);\n } catch (e) {\n return thrower(e);\n }\n if (maybePromise instanceof Promise) {\n return maybePromise._then(iterator, thrower,\n null, null, null);\n }\n }\n iterator();\n }\n iterator();\n return ret;\n }\n\n function Disposer(data, promise, context) {\n this._data = data;\n this._promise = promise;\n this._context = context;\n }\n\n Disposer.prototype.data = function () {\n return this._data;\n };\n\n Disposer.prototype.promise = function () {\n return this._promise;\n };\n\n Disposer.prototype.resource = function () {\n if (this.promise().isFulfilled()) {\n return this.promise().value();\n }\n return NULL;\n };\n\n Disposer.prototype.tryDispose = function(inspection) {\n var resource = this.resource();\n var context = this._context;\n if (context !== undefined) context._pushContext();\n var ret = resource !== NULL\n ? this.doDispose(resource, inspection) : null;\n if (context !== undefined) context._popContext();\n this._promise._unsetDisposable();\n this._data = null;\n return ret;\n };\n\n Disposer.isDisposer = function (d) {\n return (d != null &&\n typeof d.resource === \"function\" &&\n typeof d.tryDispose === \"function\");\n };\n\n function FunctionDisposer(fn, promise, context) {\n this.constructor$(fn, promise, context);\n }\n inherits(FunctionDisposer, Disposer);\n\n FunctionDisposer.prototype.doDispose = function (resource, inspection) {\n var fn = this.data();\n return fn.call(resource, resource, inspection);\n };\n\n function maybeUnwrapDisposer(value) {\n if (Disposer.isDisposer(value)) {\n this.resources[this.index]._setDisposable(value);\n return value.promise();\n }\n return value;\n }\n\n function ResourceList(length) {\n this.length = length;\n this.promise = null;\n this[length-1] = null;\n }\n\n ResourceList.prototype._resultCancelled = function() {\n var len = this.length;\n for (var i = 0; i < len; ++i) {\n var item = this[i];\n if (item instanceof Promise) {\n item.cancel();\n }\n }\n };\n\n Promise.using = function () {\n var len = arguments.length;\n if (len < 2) return apiRejection(\n \"you must pass at least 2 arguments to Promise.using\");\n var fn = arguments[len - 1];\n if (typeof fn !== \"function\") {\n return apiRejection(\"expecting a function but got \" + util.classString(fn));\n }\n var input;\n var spreadArgs = true;\n if (len === 2 && Array.isArray(arguments[0])) {\n input = arguments[0];\n len = input.length;\n spreadArgs = false;\n } else {\n input = arguments;\n len--;\n }\n var resources = new ResourceList(len);\n for (var i = 0; i < len; ++i) {\n var resource = input[i];\n if (Disposer.isDisposer(resource)) {\n var disposer = resource;\n resource = resource.promise();\n resource._setDisposable(disposer);\n } else {\n var maybePromise = tryConvertToPromise(resource);\n if (maybePromise instanceof Promise) {\n resource =\n maybePromise._then(maybeUnwrapDisposer, null, null, {\n resources: resources,\n index: i\n }, undefined);\n }\n }\n resources[i] = resource;\n }\n\n var reflectedResources = new Array(resources.length);\n for (var i = 0; i < reflectedResources.length; ++i) {\n reflectedResources[i] = Promise.resolve(resources[i]).reflect();\n }\n\n var resultPromise = Promise.all(reflectedResources)\n .then(function(inspections) {\n for (var i = 0; i < inspections.length; ++i) {\n var inspection = inspections[i];\n if (inspection.isRejected()) {\n errorObj.e = inspection.error();\n return errorObj;\n } else if (!inspection.isFulfilled()) {\n resultPromise.cancel();\n return;\n }\n inspections[i] = inspection.value();\n }\n promise._pushContext();\n\n fn = tryCatch(fn);\n var ret = spreadArgs\n ? fn.apply(undefined, inspections) : fn(inspections);\n var promiseCreated = promise._popContext();\n debug.checkForgottenReturns(\n ret, promiseCreated, \"Promise.using\", promise);\n return ret;\n });\n\n var promise = resultPromise.lastly(function() {\n var inspection = new Promise.PromiseInspection(resultPromise);\n return dispose(resources, inspection);\n });\n resources.promise = promise;\n promise._setOnCancel(resources);\n return promise;\n };\n\n Promise.prototype._setDisposable = function (disposer) {\n this._bitField = this._bitField | 131072;\n this._disposer = disposer;\n };\n\n Promise.prototype._isDisposable = function () {\n return (this._bitField & 131072) > 0;\n };\n\n Promise.prototype._getDisposer = function () {\n return this._disposer;\n };\n\n Promise.prototype._unsetDisposable = function () {\n this._bitField = this._bitField & (~131072);\n this._disposer = undefined;\n };\n\n Promise.prototype.disposer = function (fn) {\n if (typeof fn === \"function\") {\n return new FunctionDisposer(fn, this, createContext());\n }\n throw new TypeError();\n };\n\n};\n","\"use strict\";\nvar firstLineError;\ntry {throw new Error(); } catch (e) {firstLineError = e;}\nvar schedule = require(\"./schedule\");\nvar Queue = require(\"./queue\");\nvar util = require(\"./util\");\n\nfunction Async() {\n this._customScheduler = false;\n this._isTickUsed = false;\n this._lateQueue = new Queue(16);\n this._normalQueue = new Queue(16);\n this._haveDrainedQueues = false;\n this._trampolineEnabled = true;\n var self = this;\n this.drainQueues = function () {\n self._drainQueues();\n };\n this._schedule = schedule;\n}\n\nAsync.prototype.setScheduler = function(fn) {\n var prev = this._schedule;\n this._schedule = fn;\n this._customScheduler = true;\n return prev;\n};\n\nAsync.prototype.hasCustomScheduler = function() {\n return this._customScheduler;\n};\n\nAsync.prototype.enableTrampoline = function() {\n this._trampolineEnabled = true;\n};\n\nAsync.prototype.disableTrampolineIfNecessary = function() {\n if (util.hasDevTools) {\n this._trampolineEnabled = false;\n }\n};\n\nAsync.prototype.haveItemsQueued = function () {\n return this._isTickUsed || this._haveDrainedQueues;\n};\n\n\nAsync.prototype.fatalError = function(e, isNode) {\n if (isNode) {\n process.stderr.write(\"Fatal \" + (e instanceof Error ? e.stack : e) +\n \"\\n\");\n process.exit(2);\n } else {\n this.throwLater(e);\n }\n};\n\nAsync.prototype.throwLater = function(fn, arg) {\n if (arguments.length === 1) {\n arg = fn;\n fn = function () { throw arg; };\n }\n if (typeof setTimeout !== \"undefined\") {\n setTimeout(function() {\n fn(arg);\n }, 0);\n } else try {\n this._schedule(function() {\n fn(arg);\n });\n } catch (e) {\n throw new Error(\"No async scheduler available\\u000a\\u000a See http://goo.gl/MqrFmX\\u000a\");\n }\n};\n\nfunction AsyncInvokeLater(fn, receiver, arg) {\n this._lateQueue.push(fn, receiver, arg);\n this._queueTick();\n}\n\nfunction AsyncInvoke(fn, receiver, arg) {\n this._normalQueue.push(fn, receiver, arg);\n this._queueTick();\n}\n\nfunction AsyncSettlePromises(promise) {\n this._normalQueue._pushOne(promise);\n this._queueTick();\n}\n\nif (!util.hasDevTools) {\n Async.prototype.invokeLater = AsyncInvokeLater;\n Async.prototype.invoke = AsyncInvoke;\n Async.prototype.settlePromises = AsyncSettlePromises;\n} else {\n Async.prototype.invokeLater = function (fn, receiver, arg) {\n if (this._trampolineEnabled) {\n AsyncInvokeLater.call(this, fn, receiver, arg);\n } else {\n this._schedule(function() {\n setTimeout(function() {\n fn.call(receiver, arg);\n }, 100);\n });\n }\n };\n\n Async.prototype.invoke = function (fn, receiver, arg) {\n if (this._trampolineEnabled) {\n AsyncInvoke.call(this, fn, receiver, arg);\n } else {\n this._schedule(function() {\n fn.call(receiver, arg);\n });\n }\n };\n\n Async.prototype.settlePromises = function(promise) {\n if (this._trampolineEnabled) {\n AsyncSettlePromises.call(this, promise);\n } else {\n this._schedule(function() {\n promise._settlePromises();\n });\n }\n };\n}\n\nAsync.prototype._drainQueue = function(queue) {\n while (queue.length() > 0) {\n var fn = queue.shift();\n if (typeof fn !== \"function\") {\n fn._settlePromises();\n continue;\n }\n var receiver = queue.shift();\n var arg = queue.shift();\n fn.call(receiver, arg);\n }\n};\n\nAsync.prototype._drainQueues = function () {\n this._drainQueue(this._normalQueue);\n this._reset();\n this._haveDrainedQueues = true;\n this._drainQueue(this._lateQueue);\n};\n\nAsync.prototype._queueTick = function () {\n if (!this._isTickUsed) {\n this._isTickUsed = true;\n this._schedule(this.drainQueues);\n }\n};\n\nAsync.prototype._reset = function () {\n this._isTickUsed = false;\n};\n\nmodule.exports = Async;\nmodule.exports.firstLineError = firstLineError;\n","var _ = require(\"underscore\");\nvar bluebird = require(\"bluebird/js/release/promise\")();\n\nexports.defer = defer;\nexports.when = bluebird.resolve;\nexports.resolve = bluebird.resolve;\nexports.all = bluebird.all;\nexports.props = bluebird.props;\nexports.reject = bluebird.reject;\nexports.promisify = bluebird.promisify;\nexports.mapSeries = bluebird.mapSeries;\nexports.attempt = bluebird.attempt;\n\nexports.nfcall = function(func) {\n var args = Array.prototype.slice.call(arguments, 1);\n var promisedFunc = bluebird.promisify(func);\n return promisedFunc.apply(null, args);\n};\n\nbluebird.prototype.fail = bluebird.prototype.caught;\n\nbluebird.prototype.also = function(func) {\n return this.then(function(value) {\n var returnValue = _.extend({}, value, func(value));\n return bluebird.props(returnValue);\n });\n};\n\nfunction defer() {\n var resolve;\n var reject;\n var promise = new bluebird.Promise(function(resolveArg, rejectArg) {\n resolve = resolveArg;\n reject = rejectArg;\n });\n\n return {\n resolve: resolve,\n reject: reject,\n promise: promise\n };\n}\n","exports.createBodyReader = createBodyReader;\nexports._readNumberingProperties = readNumberingProperties;\n\nvar dingbatToUnicode = require(\"dingbat-to-unicode\");\nvar _ = require(\"underscore\");\n\nvar documents = require(\"../documents\");\nvar Result = require(\"../results\").Result;\nvar warning = require(\"../results\").warning;\nvar uris = require(\"./uris\");\n\nfunction createBodyReader(options) {\n return {\n readXmlElement: function(element) {\n return new BodyReader(options).readXmlElement(element);\n },\n readXmlElements: function(elements) {\n return new BodyReader(options).readXmlElements(elements);\n }\n };\n}\n\nfunction BodyReader(options) {\n var complexFieldStack = [];\n var currentInstrText = [];\n var relationships = options.relationships;\n var contentTypes = options.contentTypes;\n var docxFile = options.docxFile;\n var files = options.files;\n var numbering = options.numbering;\n var styles = options.styles;\n\n function readXmlElements(elements) {\n var results = elements.map(readXmlElement);\n return combineResults(results);\n }\n\n function readXmlElement(element) {\n if (element.type === \"element\") {\n var handler = xmlElementReaders[element.name];\n if (handler) {\n return handler(element);\n } else if (!Object.prototype.hasOwnProperty.call(ignoreElements, element.name)) {\n var message = warning(\"An unrecognised element was ignored: \" + element.name);\n return emptyResultWithMessages([message]);\n }\n }\n return emptyResult();\n }\n\n function readParagraphIndent(element) {\n return {\n start: element.attributes[\"w:start\"] || element.attributes[\"w:left\"],\n end: element.attributes[\"w:end\"] || element.attributes[\"w:right\"],\n firstLine: element.attributes[\"w:firstLine\"],\n hanging: element.attributes[\"w:hanging\"]\n };\n }\n\n function readRunProperties(element) {\n return readRunStyle(element).map(function(style) {\n var fontSizeString = element.firstOrEmpty(\"w:sz\").attributes[\"w:val\"];\n // w:sz gives the font size in half points, so halve the value to get the size in points\n var fontSize = /^[0-9]+$/.test(fontSizeString) ? parseInt(fontSizeString, 10) / 2 : null;\n\n return {\n type: \"runProperties\",\n styleId: style.styleId,\n styleName: style.name,\n verticalAlignment: element.firstOrEmpty(\"w:vertAlign\").attributes[\"w:val\"],\n font: element.firstOrEmpty(\"w:rFonts\").attributes[\"w:ascii\"],\n fontSize: fontSize,\n isBold: readBooleanElement(element.first(\"w:b\")),\n isUnderline: readUnderline(element.first(\"w:u\")),\n isItalic: readBooleanElement(element.first(\"w:i\")),\n isStrikethrough: readBooleanElement(element.first(\"w:strike\")),\n isAllCaps: readBooleanElement(element.first(\"w:caps\")),\n isSmallCaps: readBooleanElement(element.first(\"w:smallCaps\"))\n };\n });\n }\n\n function readUnderline(element) {\n if (element) {\n var value = element.attributes[\"w:val\"];\n return value !== undefined && value !== \"false\" && value !== \"0\" && value !== \"none\";\n } else {\n return false;\n }\n }\n\n function readBooleanElement(element) {\n if (element) {\n var value = element.attributes[\"w:val\"];\n return value !== \"false\" && value !== \"0\";\n } else {\n return false;\n }\n }\n\n function readParagraphStyle(element) {\n return readStyle(element, \"w:pStyle\", \"Paragraph\", styles.findParagraphStyleById);\n }\n\n function readRunStyle(element) {\n return readStyle(element, \"w:rStyle\", \"Run\", styles.findCharacterStyleById);\n }\n\n function readTableStyle(element) {\n return readStyle(element, \"w:tblStyle\", \"Table\", styles.findTableStyleById);\n }\n\n function readStyle(element, styleTagName, styleType, findStyleById) {\n var messages = [];\n var styleElement = element.first(styleTagName);\n var styleId = null;\n var name = null;\n if (styleElement) {\n styleId = styleElement.attributes[\"w:val\"];\n if (styleId) {\n var style = findStyleById(styleId);\n if (style) {\n name = style.name;\n } else {\n messages.push(undefinedStyleWarning(styleType, styleId));\n }\n }\n }\n return elementResultWithMessages({styleId: styleId, name: name}, messages);\n }\n\n var unknownComplexField = {type: \"unknown\"};\n\n function readFldChar(element) {\n var type = element.attributes[\"w:fldCharType\"];\n if (type === \"begin\") {\n complexFieldStack.push(unknownComplexField);\n currentInstrText = [];\n } else if (type === \"end\") {\n complexFieldStack.pop();\n } else if (type === \"separate\") {\n var hyperlinkOptions = parseHyperlinkFieldCode(currentInstrText.join(''));\n var complexField = hyperlinkOptions === null ? unknownComplexField : {type: \"hyperlink\", options: hyperlinkOptions};\n complexFieldStack.pop();\n complexFieldStack.push(complexField);\n }\n return emptyResult();\n }\n\n function currentHyperlinkOptions() {\n var topHyperlink = _.last(complexFieldStack.filter(function(complexField) {\n return complexField.type === \"hyperlink\";\n }));\n return topHyperlink ? topHyperlink.options : null;\n }\n\n function parseHyperlinkFieldCode(code) {\n var externalLinkResult = /\\s*HYPERLINK \"(.*)\"/.exec(code);\n if (externalLinkResult) {\n return {href: externalLinkResult[1]};\n }\n\n var internalLinkResult = /\\s*HYPERLINK\\s+\\\\l\\s+\"(.*)\"/.exec(code);\n if (internalLinkResult) {\n return {anchor: internalLinkResult[1]};\n }\n\n return null;\n }\n\n function readInstrText(element) {\n currentInstrText.push(element.text());\n return emptyResult();\n }\n\n function readSymbol(element) {\n // See 17.3.3.30 sym (Symbol Character) of ECMA-376 4th edition Part 1\n var font = element.attributes[\"w:font\"];\n var char = element.attributes[\"w:char\"];\n var unicodeCharacter = dingbatToUnicode.hex(font, char);\n if (unicodeCharacter == null && /^F0..$/.test(char)) {\n unicodeCharacter = dingbatToUnicode.hex(font, char.substring(2));\n }\n\n if (unicodeCharacter == null) {\n return emptyResultWithMessages([warning(\n \"A w:sym element with an unsupported character was ignored: char \" + char + \" in font \" + font\n )]);\n } else {\n return elementResult(new documents.Text(unicodeCharacter.string));\n }\n }\n\n function noteReferenceReader(noteType) {\n return function(element) {\n var noteId = element.attributes[\"w:id\"];\n return elementResult(new documents.NoteReference({\n noteType: noteType,\n noteId: noteId\n }));\n };\n }\n\n function readCommentReference(element) {\n return elementResult(documents.commentReference({\n commentId: element.attributes[\"w:id\"]\n }));\n }\n\n function readChildElements(element) {\n return readXmlElements(element.children);\n }\n\n var xmlElementReaders = {\n \"w:p\": function(element) {\n return readXmlElements(element.children)\n .map(function(children) {\n var properties = _.find(children, isParagraphProperties);\n return new documents.Paragraph(\n children.filter(negate(isParagraphProperties)),\n properties\n );\n })\n .insertExtra();\n },\n \"w:pPr\": function(element) {\n return readParagraphStyle(element).map(function(style) {\n return {\n type: \"paragraphProperties\",\n styleId: style.styleId,\n styleName: style.name,\n alignment: element.firstOrEmpty(\"w:jc\").attributes[\"w:val\"],\n numbering: readNumberingProperties(style.styleId, element.firstOrEmpty(\"w:numPr\"), numbering),\n indent: readParagraphIndent(element.firstOrEmpty(\"w:ind\"))\n };\n });\n },\n \"w:r\": function(element) {\n return readXmlElements(element.children)\n .map(function(children) {\n var properties = _.find(children, isRunProperties);\n children = children.filter(negate(isRunProperties));\n\n var hyperlinkOptions = currentHyperlinkOptions();\n if (hyperlinkOptions !== null) {\n children = [new documents.Hyperlink(children, hyperlinkOptions)];\n }\n\n return new documents.Run(children, properties);\n });\n },\n \"w:rPr\": readRunProperties,\n \"w:fldChar\": readFldChar,\n \"w:instrText\": readInstrText,\n \"w:t\": function(element) {\n return elementResult(new documents.Text(element.text()));\n },\n \"w:tab\": function(element) {\n return elementResult(new documents.Tab());\n },\n \"w:noBreakHyphen\": function() {\n return elementResult(new documents.Text(\"\\u2011\"));\n },\n \"w:softHyphen\": function(element) {\n return elementResult(new documents.Text(\"\\u00AD\"));\n },\n \"w:sym\": readSymbol,\n \"w:hyperlink\": function(element) {\n var relationshipId = element.attributes[\"r:id\"];\n var anchor = element.attributes[\"w:anchor\"];\n return readXmlElements(element.children).map(function(children) {\n function create(options) {\n var targetFrame = element.attributes[\"w:tgtFrame\"] || null;\n\n return new documents.Hyperlink(\n children,\n _.extend({targetFrame: targetFrame}, options)\n );\n }\n\n if (relationshipId) {\n var href = relationships.findTargetByRelationshipId(relationshipId);\n if (anchor) {\n href = uris.replaceFragment(href, anchor);\n }\n return create({href: href});\n } else if (anchor) {\n return create({anchor: anchor});\n } else {\n return children;\n }\n });\n },\n \"w:tbl\": readTable,\n \"w:tr\": readTableRow,\n \"w:tc\": readTableCell,\n \"w:footnoteReference\": noteReferenceReader(\"footnote\"),\n \"w:endnoteReference\": noteReferenceReader(\"endnote\"),\n \"w:commentReference\": readCommentReference,\n \"w:br\": function(element) {\n var breakType = element.attributes[\"w:type\"];\n if (breakType == null || breakType === \"textWrapping\") {\n return elementResult(documents.lineBreak);\n } else if (breakType === \"page\") {\n return elementResult(documents.pageBreak);\n } else if (breakType === \"column\") {\n return elementResult(documents.columnBreak);\n } else {\n return emptyResultWithMessages([warning(\"Unsupported break type: \" + breakType)]);\n }\n },\n \"w:bookmarkStart\": function(element){\n var name = element.attributes[\"w:name\"];\n if (name === \"_GoBack\") {\n return emptyResult();\n } else {\n return elementResult(new documents.BookmarkStart({name: name}));\n }\n },\n\n \"mc:AlternateContent\": function(element) {\n return readChildElements(element.first(\"mc:Fallback\"));\n },\n\n \"w:sdt\": function(element) {\n return readXmlElements(element.firstOrEmpty(\"w:sdtContent\").children);\n },\n\n \"w:ins\": readChildElements,\n \"w:object\": readChildElements,\n \"w:smartTag\": readChildElements,\n \"w:drawing\": readChildElements,\n \"w:pict\": function(element) {\n return readChildElements(element).toExtra();\n },\n \"v:roundrect\": readChildElements,\n \"v:shape\": readChildElements,\n \"v:textbox\": readChildElements,\n \"w:txbxContent\": readChildElements,\n \"wp:inline\": readDrawingElement,\n \"wp:anchor\": readDrawingElement,\n \"v:imagedata\": readImageData,\n \"v:group\": readChildElements,\n \"v:rect\": readChildElements\n };\n\n return {\n readXmlElement: readXmlElement,\n readXmlElements: readXmlElements\n };\n\n\n function readTable(element) {\n var propertiesResult = readTableProperties(element.firstOrEmpty(\"w:tblPr\"));\n return readXmlElements(element.children)\n .flatMap(calculateRowSpans)\n .flatMap(function(children) {\n return propertiesResult.map(function(properties) {\n return documents.Table(children, properties);\n });\n });\n }\n\n function readTableProperties(element) {\n return readTableStyle(element).map(function(style) {\n return {\n styleId: style.styleId,\n styleName: style.name\n };\n });\n }\n\n function readTableRow(element) {\n var properties = element.firstOrEmpty(\"w:trPr\");\n var isHeader = !!properties.first(\"w:tblHeader\");\n return readXmlElements(element.children).map(function(children) {\n return documents.TableRow(children, {isHeader: isHeader});\n });\n }\n\n function readTableCell(element) {\n return readXmlElements(element.children).map(function(children) {\n var properties = element.firstOrEmpty(\"w:tcPr\");\n\n var gridSpan = properties.firstOrEmpty(\"w:gridSpan\").attributes[\"w:val\"];\n var colSpan = gridSpan ? parseInt(gridSpan, 10) : 1;\n\n var cell = documents.TableCell(children, {colSpan: colSpan});\n cell._vMerge = readVMerge(properties);\n return cell;\n });\n }\n\n function readVMerge(properties) {\n var element = properties.first(\"w:vMerge\");\n if (element) {\n var val = element.attributes[\"w:val\"];\n return val === \"continue\" || !val;\n } else {\n return null;\n }\n }\n\n function calculateRowSpans(rows) {\n var unexpectedNonRows = _.any(rows, function(row) {\n return row.type !== documents.types.tableRow;\n });\n if (unexpectedNonRows) {\n return elementResultWithMessages(rows, [warning(\n \"unexpected non-row element in table, cell merging may be incorrect\"\n )]);\n }\n var unexpectedNonCells = _.any(rows, function(row) {\n return _.any(row.children, function(cell) {\n return cell.type !== documents.types.tableCell;\n });\n });\n if (unexpectedNonCells) {\n return elementResultWithMessages(rows, [warning(\n \"unexpected non-cell element in table row, cell merging may be incorrect\"\n )]);\n }\n\n var columns = {};\n\n rows.forEach(function(row) {\n var cellIndex = 0;\n row.children.forEach(function(cell) {\n if (cell._vMerge && columns[cellIndex]) {\n columns[cellIndex].rowSpan++;\n } else {\n columns[cellIndex] = cell;\n cell._vMerge = false;\n }\n cellIndex += cell.colSpan;\n });\n });\n\n rows.forEach(function(row) {\n row.children = row.children.filter(function(cell) {\n return !cell._vMerge;\n });\n row.children.forEach(function(cell) {\n delete cell._vMerge;\n });\n });\n\n return elementResult(rows);\n }\n\n function readDrawingElement(element) {\n var blips = element\n .getElementsByTagName(\"a:graphic\")\n .getElementsByTagName(\"a:graphicData\")\n .getElementsByTagName(\"pic:pic\")\n .getElementsByTagName(\"pic:blipFill\")\n .getElementsByTagName(\"a:blip\");\n\n return combineResults(blips.map(readBlip.bind(null, element)));\n }\n\n function readBlip(element, blip) {\n var properties = element.first(\"wp:docPr\").attributes;\n var altText = isBlank(properties.descr) ? properties.title : properties.descr;\n var blipImageFile = findBlipImageFile(blip);\n if (blipImageFile === null) {\n return emptyResultWithMessages([warning(\"Could not find image file for a:blip element\")]);\n } else {\n return readImage(blipImageFile, altText);\n }\n }\n\n function isBlank(value) {\n return value == null || /^\\s*$/.test(value);\n }\n\n function findBlipImageFile(blip) {\n var embedRelationshipId = blip.attributes[\"r:embed\"];\n var linkRelationshipId = blip.attributes[\"r:link\"];\n if (embedRelationshipId) {\n return findEmbeddedImageFile(embedRelationshipId);\n } else if (linkRelationshipId) {\n var imagePath = relationships.findTargetByRelationshipId(linkRelationshipId);\n return {\n path: imagePath,\n read: files.read.bind(files, imagePath)\n };\n } else {\n return null;\n }\n }\n\n function readImageData(element) {\n var relationshipId = element.attributes['r:id'];\n\n if (relationshipId) {\n return readImage(\n findEmbeddedImageFile(relationshipId),\n element.attributes[\"o:title\"]);\n } else {\n return emptyResultWithMessages([warning(\"A v:imagedata element without a relationship ID was ignored\")]);\n }\n }\n\n function findEmbeddedImageFile(relationshipId) {\n var path = uris.uriToZipEntryName(\"word\", relationships.findTargetByRelationshipId(relationshipId));\n return {\n path: path,\n read: docxFile.read.bind(docxFile, path)\n };\n }\n\n function readImage(imageFile, altText) {\n var contentType = contentTypes.findContentType(imageFile.path);\n\n var image = documents.Image({\n readImage: imageFile.read,\n altText: altText,\n contentType: contentType\n });\n var warnings = supportedImageTypes[contentType] ?\n [] : warning(\"Image of type \" + contentType + \" is unlikely to display in web browsers\");\n return elementResultWithMessages(image, warnings);\n }\n\n function undefinedStyleWarning(type, styleId) {\n return warning(\n type + \" style with ID \" + styleId + \" was referenced but not defined in the document\");\n }\n}\n\n\nfunction readNumberingProperties(styleId, element, numbering) {\n if (styleId != null) {\n var levelByStyleId = numbering.findLevelByParagraphStyleId(styleId);\n if (levelByStyleId != null) {\n return levelByStyleId;\n }\n }\n\n var level = element.firstOrEmpty(\"w:ilvl\").attributes[\"w:val\"];\n var numId = element.firstOrEmpty(\"w:numId\").attributes[\"w:val\"];\n if (level === undefined || numId === undefined) {\n return null;\n } else {\n return numbering.findLevel(numId, level);\n }\n}\n\nvar supportedImageTypes = {\n \"image/png\": true,\n \"image/gif\": true,\n \"image/jpeg\": true,\n \"image/svg+xml\": true,\n \"image/tiff\": true\n};\n\nvar ignoreElements = {\n \"office-word:wrap\": true,\n \"v:shadow\": true,\n \"v:shapetype\": true,\n \"w:annotationRef\": true,\n \"w:bookmarkEnd\": true,\n \"w:sectPr\": true,\n \"w:proofErr\": true,\n \"w:lastRenderedPageBreak\": true,\n \"w:commentRangeStart\": true,\n \"w:commentRangeEnd\": true,\n \"w:del\": true,\n \"w:footnoteRef\": true,\n \"w:endnoteRef\": true,\n \"w:tblPr\": true,\n \"w:tblGrid\": true,\n \"w:trPr\": true,\n \"w:tcPr\": true\n};\n\nfunction isParagraphProperties(element) {\n return element.type === \"paragraphProperties\";\n}\n\nfunction isRunProperties(element) {\n return element.type === \"runProperties\";\n}\n\nfunction negate(predicate) {\n return function(value) {\n return !predicate(value);\n };\n}\n\n\nfunction emptyResultWithMessages(messages) {\n return new ReadResult(null, null, messages);\n}\n\nfunction emptyResult() {\n return new ReadResult(null);\n}\n\nfunction elementResult(element) {\n return new ReadResult(element);\n}\n\nfunction elementResultWithMessages(element, messages) {\n return new ReadResult(element, null, messages);\n}\n\nfunction ReadResult(element, extra, messages) {\n this.value = element || [];\n this.extra = extra;\n this._result = new Result({\n element: this.value,\n extra: extra\n }, messages);\n this.messages = this._result.messages;\n}\n\nReadResult.prototype.toExtra = function() {\n return new ReadResult(null, joinElements(this.extra, this.value), this.messages);\n};\n\nReadResult.prototype.insertExtra = function() {\n var extra = this.extra;\n if (extra && extra.length) {\n return new ReadResult(joinElements(this.value, extra), null, this.messages);\n } else {\n return this;\n }\n};\n\nReadResult.prototype.map = function(func) {\n var result = this._result.map(function(value) {\n return func(value.element);\n });\n return new ReadResult(result.value, this.extra, result.messages);\n};\n\nReadResult.prototype.flatMap = function(func) {\n var result = this._result.flatMap(function(value) {\n return func(value.element)._result;\n });\n return new ReadResult(result.value.element, joinElements(this.extra, result.value.extra), result.messages);\n};\n\nfunction combineResults(results) {\n var result = Result.combine(_.pluck(results, \"_result\"));\n return new ReadResult(\n _.flatten(_.pluck(result.value, \"element\")),\n _.filter(_.flatten(_.pluck(result.value, \"extra\")), identity),\n result.messages\n );\n}\n\nfunction joinElements(first, second) {\n return _.flatten([first, second]);\n}\n\nfunction identity(value) {\n return value;\n}\n",";(function (sax) { // wrapper for non-node envs\n sax.parser = function (strict, opt) { return new SAXParser(strict, opt) }\n sax.SAXParser = SAXParser\n sax.SAXStream = SAXStream\n sax.createStream = createStream\n\n // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns.\n // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)),\n // since that's the earliest that a buffer overrun could occur. This way, checks are\n // as rare as required, but as often as necessary to ensure never crossing this bound.\n // Furthermore, buffers are only tested at most once per write(), so passing a very\n // large string into write() might have undesirable effects, but this is manageable by\n // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme\n // edge case, result in creating at most one complete copy of the string passed in.\n // Set to Infinity to have unlimited buffers.\n sax.MAX_BUFFER_LENGTH = 64 * 1024\n\n var buffers = [\n 'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype',\n 'procInstName', 'procInstBody', 'entity', 'attribName',\n 'attribValue', 'cdata', 'script'\n ]\n\n sax.EVENTS = [\n 'text',\n 'processinginstruction',\n 'sgmldeclaration',\n 'doctype',\n 'comment',\n 'attribute',\n 'opentag',\n 'closetag',\n 'opencdata',\n 'cdata',\n 'closecdata',\n 'error',\n 'end',\n 'ready',\n 'script',\n 'opennamespace',\n 'closenamespace'\n ]\n\n function SAXParser (strict, opt) {\n if (!(this instanceof SAXParser)) {\n return new SAXParser(strict, opt)\n }\n\n var parser = this\n clearBuffers(parser)\n parser.q = parser.c = ''\n parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH\n parser.opt = opt || {}\n parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags\n parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase'\n parser.tags = []\n parser.closed = parser.closedRoot = parser.sawRoot = false\n parser.tag = parser.error = null\n parser.strict = !!strict\n parser.noscript = !!(strict || parser.opt.noscript)\n parser.state = S.BEGIN\n parser.strictEntities = parser.opt.strictEntities\n parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES)\n parser.attribList = []\n\n // namespaces form a prototype chain.\n // it always points at the current tag,\n // which protos to its parent tag.\n if (parser.opt.xmlns) {\n parser.ns = Object.create(rootNS)\n }\n\n // mostly just for error reporting\n parser.trackPosition = parser.opt.position !== false\n if (parser.trackPosition) {\n parser.position = parser.line = parser.column = 0\n }\n emit(parser, 'onready')\n }\n\n if (!Object.create) {\n Object.create = function (o) {\n function F () {}\n F.prototype = o\n var newf = new F()\n return newf\n }\n }\n\n if (!Object.keys) {\n Object.keys = function (o) {\n var a = []\n for (var i in o) if (o.hasOwnProperty(i)) a.push(i)\n return a\n }\n }\n\n function checkBufferLength (parser) {\n var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)\n var maxActual = 0\n for (var i = 0, l = buffers.length; i < l; i++) {\n var len = parser[buffers[i]].length\n if (len > maxAllowed) {\n // Text/cdata nodes can get big, and since they're buffered,\n // we can get here under normal conditions.\n // Avoid issues by emitting the text node now,\n // so at least it won't get any bigger.\n switch (buffers[i]) {\n case 'textNode':\n closeText(parser)\n break\n\n case 'cdata':\n emitNode(parser, 'oncdata', parser.cdata)\n parser.cdata = ''\n break\n\n case 'script':\n emitNode(parser, 'onscript', parser.script)\n parser.script = ''\n break\n\n default:\n error(parser, 'Max buffer length exceeded: ' + buffers[i])\n }\n }\n maxActual = Math.max(maxActual, len)\n }\n // schedule the next check for the earliest possible buffer overrun.\n var m = sax.MAX_BUFFER_LENGTH - maxActual\n parser.bufferCheckPosition = m + parser.position\n }\n\n function clearBuffers (parser) {\n for (var i = 0, l = buffers.length; i < l; i++) {\n parser[buffers[i]] = ''\n }\n }\n\n function flushBuffers (parser) {\n closeText(parser)\n if (parser.cdata !== '') {\n emitNode(parser, 'oncdata', parser.cdata)\n parser.cdata = ''\n }\n if (parser.script !== '') {\n emitNode(parser, 'onscript', parser.script)\n parser.script = ''\n }\n }\n\n SAXParser.prototype = {\n end: function () { end(this) },\n write: write,\n resume: function () { this.error = null; return this },\n close: function () { return this.write(null) },\n flush: function () { flushBuffers(this) }\n }\n\n var Stream\n try {\n Stream = require('stream').Stream\n } catch (ex) {\n Stream = function () {}\n }\n\n var streamWraps = sax.EVENTS.filter(function (ev) {\n return ev !== 'error' && ev !== 'end'\n })\n\n function createStream (strict, opt) {\n return new SAXStream(strict, opt)\n }\n\n function SAXStream (strict, opt) {\n if (!(this instanceof SAXStream)) {\n return new SAXStream(strict, opt)\n }\n\n Stream.apply(this)\n\n this._parser = new SAXParser(strict, opt)\n this.writable = true\n this.readable = true\n\n var me = this\n\n this._parser.onend = function () {\n me.emit('end')\n }\n\n this._parser.onerror = function (er) {\n me.emit('error', er)\n\n // if didn't throw, then means error was handled.\n // go ahead and clear error, so we can write again.\n me._parser.error = null\n }\n\n this._decoder = null\n\n streamWraps.forEach(function (ev) {\n Object.defineProperty(me, 'on' + ev, {\n get: function () {\n return me._parser['on' + ev]\n },\n set: function (h) {\n if (!h) {\n me.removeAllListeners(ev)\n me._parser['on' + ev] = h\n return h\n }\n me.on(ev, h)\n },\n enumerable: true,\n configurable: false\n })\n })\n }\n\n SAXStream.prototype = Object.create(Stream.prototype, {\n constructor: {\n value: SAXStream\n }\n })\n\n SAXStream.prototype.write = function (data) {\n if (typeof Buffer === 'function' &&\n typeof Buffer.isBuffer === 'function' &&\n Buffer.isBuffer(data)) {\n if (!this._decoder) {\n var SD = require('string_decoder').StringDecoder\n this._decoder = new SD('utf8')\n }\n data = this._decoder.write(data)\n }\n\n this._parser.write(data.toString())\n this.emit('data', data)\n return true\n }\n\n SAXStream.prototype.end = function (chunk) {\n if (chunk && chunk.length) {\n this.write(chunk)\n }\n this._parser.end()\n return true\n }\n\n SAXStream.prototype.on = function (ev, handler) {\n var me = this\n if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) {\n me._parser['on' + ev] = function () {\n var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments)\n args.splice(0, 0, ev)\n me.emit.apply(me, args)\n }\n }\n\n return Stream.prototype.on.call(me, ev, handler)\n }\n\n // character classes and tokens\n var whitespace = '\\r\\n\\t '\n\n // this really needs to be replaced with character classes.\n // XML allows all manner of ridiculous numbers and digits.\n var number = '0124356789'\n var letter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'\n\n // (Letter | \"_\" | \":\")\n var quote = '\\'\"'\n var attribEnd = whitespace + '>'\n var CDATA = '[CDATA['\n var DOCTYPE = 'DOCTYPE'\n var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'\n var XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/'\n var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE }\n\n // turn all the string character sets into character class objects.\n whitespace = charClass(whitespace)\n number = charClass(number)\n letter = charClass(letter)\n\n // http://www.w3.org/TR/REC-xml/#NT-NameStartChar\n // This implementation works on strings, a single character at a time\n // as such, it cannot ever support astral-plane characters (10000-EFFFF)\n // without a significant breaking change to either this parser, or the\n // JavaScript language. Implementation of an emoji-capable xml parser\n // is left as an exercise for the reader.\n var nameStart = /[:_A-Za-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]/\n\n var nameBody = /[:_A-Za-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u00B7\\u0300-\\u036F\\u203F-\\u2040\\.\\d-]/\n\n var entityStart = /[#:_A-Za-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]/\n var entityBody = /[#:_A-Za-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\u00B7\\u0300-\\u036F\\u203F-\\u2040\\.\\d-]/\n\n quote = charClass(quote)\n attribEnd = charClass(attribEnd)\n\n function charClass (str) {\n return str.split('').reduce(function (s, c) {\n s[c] = true\n return s\n }, {})\n }\n\n function isRegExp (c) {\n return Object.prototype.toString.call(c) === '[object RegExp]'\n }\n\n function is (charclass, c) {\n return isRegExp(charclass) ? !!c.match(charclass) : charclass[c]\n }\n\n function not (charclass, c) {\n return !is(charclass, c)\n }\n\n var S = 0\n sax.STATE = {\n BEGIN: S++, // leading byte order mark or whitespace\n BEGIN_WHITESPACE: S++, // leading whitespace\n TEXT: S++, // general stuff\n TEXT_ENTITY: S++, // & and such.\n OPEN_WAKA: S++, // <\n SGML_DECL: S++, // \n SCRIPT: S++, //