diff --git a/dist/htmlParser.es6.js b/dist/htmlParser.es6.js index e61684c..83e52f8 100644 --- a/dist/htmlParser.es6.js +++ b/dist/htmlParser.es6.js @@ -136,6 +136,11 @@ function tokenize(html) { const maxTime = Date.now() + 1000; while (string) { + if (string.indexOf("") + 3; + string = string.substring(lastIndex); + continue + } if (string.indexOf("") + 3; + string = string.substring(lastIndex); + continue; + } if (string.indexOf("=i)break}else{var u=n.match(s);if(!u)continue;n=n.substring(u[0].length);var c=u[1],l=u[2],p=t(c)?new g(c,l):new y(c,l);r.push(p)}else{var h=n.match(f);if(!h)continue;n=n.substring(h[0].length);var b=h[1];if(t(b))continue;r.push(new v(b))}return r}function c(e){return a(u(e))}var s=/^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,f=/^<\/([-A-Za-z0-9_]+)[^>]*>/,l=e("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr"),p=e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),h=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},b=function(){function e(e,t){for(var n=0;n\s]+)))?/g,function(e,r){var i=Array.prototype.slice.call(arguments),o=i[2]?i[2]:i[3]?i[3]:i[4]?i[4]:n(r)?r:"";t[r]=o.replace(/(^|[^\\])"/g,'$1\\"')}),t}}]),e}(),g=function(e){function t(e,n){return h(this,t),m(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return d(t,e),t}(y),v=function e(t){h(this,e),this.name=t},w=function e(t){h(this,e),this.text=t},_="Element",O="Text";return c}); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.htmlParser=t()}(this,function(){"use strict";function e(e){return e.split(",").reduce(function(e,t){return e[t]=!0,e},{})}function t(e){return!!l[e]}function n(e){return!!p[e]}function r(e){var t=e.name,n=e.attributes;return e instanceof g?{type:_,tagName:t,attributes:n}:{type:_,tagName:t,attributes:n,children:[]}}function i(e){var t=e.text;return{type:x,content:t}}function o(e,t){switch(e){case _:return r(t);case x:return i(t)}}function a(e){var t={tag:"root",children:[]},n=[t];n.last=function(){return n[n.length-1]};for(var r=0;r=i)break}else{var u=n.match(c);if(!u)continue;n=n.substring(u[0].length);var s=u[1],l=u[2],p=t(s)?new g(s,l):new y(s,l);r.push(p)}else{var h=n.match(f);if(!h)continue;n=n.substring(h[0].length);var b=h[1];if(t(b))continue;r.push(new v(b))}else{var d=n.indexOf("--\x3e")+3;n=n.substring(d)}return r}function s(e){return a(u(e))}var c=/^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,f=/^<\/([-A-Za-z0-9_]+)[^>]*>/,l=e("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr"),p=e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),h=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},b=function(){function e(e,t){for(var n=0;n\s]+)))?/g,function(e,r){var i=Array.prototype.slice.call(arguments),o=i[2]?i[2]:i[3]?i[3]:i[4]?i[4]:n(r)?r:"";t[r]=o.replace(/(^|[^\\])"/g,'$1\\"')}),t}}]),e}(),g=function(e){function t(e,n){return h(this,t),m(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return d(t,e),t}(y),v=function e(t){h(this,e),this.name=t},w=function e(t){h(this,e),this.text=t},_="Element",x="Text";return s}); diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 565ec3e..cc1a9d0 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -8,6 +8,11 @@ export function tokenize(html) { const maxTime = Date.now() + 1000 while (string) { + if (string.indexOf("") + 3 + string = string.substring(lastIndex) + continue + } if (string.indexOf(" { t.deepEqual(div.children[0], br) }) +test('should pass the comment case', t=> { + const html = "
" + const div = htmlParser(html).children[0] + t.deepEqual(div.children.length, 0) +}) + test('should pass the nested element case', t=> { const html = "
a

bc

" const tree = {