24 lines
16 KiB
JavaScript
24 lines
16 KiB
JavaScript
|
/***********************************************
|
||
|
Copyright 2010 - 2012 Chris Winberry <chris@winberry.net>. All rights reserved.
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
of this software and associated documentation files (the "Software"), to
|
||
|
deal in the Software without restriction, including without limitation the
|
||
|
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||
|
sell copies of the Software, and to permit persons to whom the Software is
|
||
|
furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||
|
IN THE SOFTWARE.
|
||
|
***********************************************/
|
||
|
/* v2.0.0 */
|
||
|
|
||
|
!function(){function t(t,e){var a=function(){};a.prototype=e.prototype,t.super_=e,t.prototype=new a,t.prototype.constructor=t}function e(t,e){this._options=e||{},this._validateBuilder(t);this._builder=t,this.reset()}function a(t,e){this.reset(),this._options=e||{},void 0===this._options.ignoreWhitespace&&(this._options.ignoreWhitespace=!1),void 0===this._options.includeLocation&&(this._options.includeLocation=!1),void 0===this._options.verbose&&(this._options.verbose=!0),void 0===this._options.enforceEmptyTags&&(this._options.enforceEmptyTags=!0),void 0===this._options.caseSensitiveTags&&(this._options.caseSensitiveTags=!1),void 0===this._options.caseSensitiveAttr&&(this._options.caseSensitiveAttr=!1),"function"==typeof t&&(this._callback=t)}function n(t){n.super_.call(this,t,{ignoreWhitespace:!0,verbose:!1,enforceEmptyTags:!1,caseSensitiveTags:!0})}var i;if("undefined"!=typeof module&&void 0!==module.exports)i=module.exports;else{if(i={},this.Tautologistics||(this.Tautologistics={}),this.Tautologistics.NodeHtmlParser)return;this.Tautologistics.NodeHtmlParser=i}var s={Text:"text",Tag:"tag",Attr:"attr",CData:"cdata",Doctype:"doctype",Comment:"comment"};"undefined"!=typeof module&&void 0!==module.exports&&(t(e,require("stream")),e.prototype.writable=!0,e.prototype.write=function(t){t instanceof Buffer&&(t=t.toString()),this.parseChunk(t)},e.prototype.end=function(t){arguments.length&&this.write(t),this.writable=!1,this.done()},e.prototype.destroy=function(){this.writable=!1}),e.prototype.reset=function(){this._state={mode:s.Text,pos:0,data:null,pendingText:null,pendingWrite:null,lastTag:null,isScript:!1,needData:!1,output:[],done:!1},this._builder.reset()},e.prototype.parseChunk=function(t){for(this._state.needData=!1,this._state.data=null!==this._state.data?this._state.data.substr(this.pos)+t:t;this._state.pos<this._state.data.length&&!this._state.needData;)this._parse(this._state)},e.prototype.parseComplete=function(t){this.reset(),this.parseChunk(t),this.done()},e.prototype.done=function(){this._state.done=!0,this._parse(this._state),this._flushWrite(),this._builder.done()},e.prototype._validateBuilder=function(t){if("object"!=typeof t)throw new Error("Builder is not an object");if("function"!=typeof t.reset)throw new Error("Builder method 'reset' is invalid");if("function"!=typeof t.done)throw new Error("Builder method 'done' is invalid");if("function"!=typeof t.write)throw new Error("Builder method 'write' is invalid");if("function"!=typeof t.error)throw new Error("Builder method 'error' is invalid")},e.prototype._parse=function(){switch(this._state.mode){case s.Text:return this._parseText(this._state);case s.Tag:return this._parseTag(this._state);case s.Attr:return this._parseAttr(this._state);case s.CData:return this._parseCData(this._state);case s.Doctype:return this._parseDoctype(this._state);case s.Comment:return this._parseComment(this._state)}},e.prototype._writePending=function(t){this._state.pendingWrite||(this._state.pendingWrite=[]),this._state.pendingWrite.push(t)},e.prototype._flushWrite=function(){if(this._state.pendingWrite){for(var t=0,e=this._state.pendingWrite.length;t<e;t++){var a=this._state.pendingWrite[t];this._builder.write(a)}this._state.pendingWrite=null}},e.prototype._write=function(t){this._flushWrite(),this._builder.write(t)},e._re_parseText_scriptClose=/<\s*\/\s*script/gi,e.prototype._parseText=function(){var t,a=this._state;a.isScript?(e._re_parseText_scriptClose.lastIndex=a.pos,t=(t=e._re_parseText_scriptClose.exec(a.data))?t.index:-1):t=a.data.indexOf("<",a.pos);var n=-1===t?a.data.substring(a.pos,a.data.length):a.data.substring(a.pos,t);if(t<0&&a.done&&(t=a.data.length),t<0){if(a.isScript)return void(a.needData=!0);a.pendingText||(a.pendingText=[]),a.pendingText.push(a.data.substring(a.pos,a.data.length)),a.pos=a.data.length}else a.pendingText?(a.pendingText.push(a.data.substring(a.pos,t)),n=a.pendingText.join(""),a.pendingText=null):n=a.data.substring(a.pos,t),""!==n&&this._write({type:s.Text,data:n}),a.pos=t+1,a.mode=s.Tag},e.re_parseTag=/\s*(\/?)\s*([^\s>\/]+)(\s*)\??(>?)/g,e.proto
|