lys-markdown-parser
Advanced tools
Comparing version 1.1.6 to 1.1.7
@@ -44,11 +44,10 @@ 'use strict'; | ||
* diff array | ||
* 1. 先删除,根据type是否在nextNode里存在 | ||
* 2. diff filterPrevChildren与 nextChildren | ||
* 如果前后两次是node位置发生变化【比较复杂】 | ||
* 1. 先删除在nextNode里不存在的type | ||
* 2. 保留在nextNode里存在的type | ||
* 3. 删除剩余的元素,最后得到 prevKeepArr | ||
* 4. nextNode 与 prevKeepArr 最对比,进行move/add操作, | ||
* 需要注意的是在获取操作的过程,需要丢prevKeepArr进行同步更新 | ||
* 不然会导致操作混乱,数据不一致 | ||
* 5. 返回diff结果 | ||
* | ||
* 后一次插入了新的nodes【相对简单】 | ||
* [1 2 3 4] [1 2 6 3 4] | ||
* | ||
* 每种类型的个数是一致的,那么就是移动 | ||
* 每种类型的个数是不一致的,那么就是 | ||
*/ | ||
@@ -1166,3 +1165,3 @@ | ||
ele.style.cssText = ";position: relative; max-width: ".concat(width, "px; overflow: hidden; background: rgb(219, 221, 215);"); | ||
ele.innerHTML = "<div style=\"padding-top: ".concat(height / width * 100, "%;\">\n <img ").concat(LY.lazyLoad.caches.includes(src) ? "src=\"".concat(src, "\" data-img-cache=\"true\"") : '', "\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(node.src, "\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>"); | ||
ele.innerHTML = "<div style=\"padding-top: ".concat(height / width * 100, "%;\">\n <img ").concat(LY.lazyLoad.caches.includes(src) ? "src=\"".concat(src, "\" data-img-cache=\"true\"") : '', "\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(node.src, "\"\n data-src=\"").concat(node.src, "\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>"); | ||
break; | ||
@@ -1169,0 +1168,0 @@ } else { |
@@ -1,1 +0,1 @@ | ||
"use strict";function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],!(0<=b.indexOf(c))&&Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _objectSpread(a){for(var b=1;b<arguments.length;b++){var c=null==arguments[b]?{}:arguments[b],d=Object.keys(c);"function"==typeof Object.getOwnPropertySymbols&&(d=d.concat(Object.getOwnPropertySymbols(c).filter(function(a){return Object.getOwnPropertyDescriptor(c,a).enumerable}))),d.forEach(function(b){_defineProperty(a,b,c[b])})}return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}var fuckMD=function(a){"use strict";function b(a,b){if(!a)return{type:"add",prevNode:a,nextNode:b};if(!b)return{type:"del",prevNode:a,nextNode:b};if(a.type!==b.type)return{type:"replace",prevNode:a,nextNode:b};var e={type:"update",prevNode:a,nextNode:b,propsChange:[],children:[]},f=d(a,b);if(f.length){var g;(g=e.propsChange).push.apply(g,_toConsumableArray(f))}return(e.children=c(a,b).filter(function(a){return a}),0<e.propsChange.length+e.children.length)?e:(b.__htmlNode=a.__htmlNode,b.__update=a.__update,e)}function c(a,c){var d=a.children,e=void 0===d?[]:d,f=c.children,g=void 0===f?[]:f,h=[],i=[],j=e.filter(function(a){return!!g.some(function(b){return b.type===a.type})||(h.push(b(a,null)),!1)});g.forEach(function(a){j.some(function(b,c){return b.type===a.type&&(j[c]={isDel:!0,ele:b},!0)})}),j.filter(function(a){return!a.isDel}).forEach(function(a){return h.push(b(a,null))});var k=j.filter(function(a){return a.isDel}).map(function(a){return a.ele});return g.forEach(function(a,c){var d=k.some(function(d,e){if(d.type===a.type){k.splice(e,1),k.splice(c>e?c-1:c,0,{used:!0,ele:d}),e!==c&&i.push({type:"move",prevNode:d,nextNode:a,current:e,moveTo:c>e?c+1:c});var f=b(d,a);return i.push(f),!0}return!1});if(!d){k.splice(c,0,{add:!0,item:a});var e=b(null,a);i.push(_objectSpread({},e,{moveTo:c}))}}),h.concat(i,[],[])}function d(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=Object.keys(a),d=Object.keys(b),e=[];return c.forEach(function(c){return["__htmlNode","__parent","__update","children","type"].includes(c)?void 0:d.includes(c)?void(a[c]!==b[c]&&e.push({type:"change",key:c,prevNode:a,nextNode:b})):void e.push({type:"del",key:c,prevNode:a,nextNode:b})}),d.forEach(function(d){c.includes(d)||e.push({type:"add",key:d,prevNode:a,nextNode:b})}),e}function e(){for(var a,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",e=0,f=-1,g=0,h=function(a){return b.slice(e,e+a.length)===a};e<b.length;){if(a=b[e],!g)if(!a.trim()){e+=1;continue}else if(h(c)){f=e,g+=1,e+=c.length;continue}else return[void 0,b];if(h(d)?(g-=1,e+=d.length):h(c)?(g+=1,e+=c.length):e+=1,!g)return[b.slice(f+c.length,e-d.length),b.slice(e)]}return[void 0,b]}function f(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",c=a.indexOf(b);return[a.slice(0,c),a.slice(c+b.length)]}function g(){function a(a,b){var c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},d=c.isPush,e=n;n=a,a.__parent=n,b&&b(),n=e,(void 0===d||d)&&n.children.push(a)}function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";l=l.slice(a.length)}function c(a){return[q.head,q.ul,q.code,q.queto].some(function(b){return b.test(a)})}function d(){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,c=a.split("\n")[b].trim();return /^\|.+\|$/.test(c)?c.split("|").slice(1,-1):[]}var d=b(l,0),e=b(l,1),f=d.length;if(0!=f&&d.length==e.length&&e.every(function(a){return /^-+$/.test(a.replace(/\s/g,""))})){return a({type:"table",children:[]},function(){l=l.replace(/(.+)\n?/,function(b,c){return a({type:"thead",children:[]},function(){a({type:"tr",children:[]},function(){c.trim().split("|").slice(1,-1).map(function(b){a({type:"th",children:[]},function(){h(b)})})})}),""}),l=l.replace(/.+\n?/,"");a({type:"tbody",children:[]},function(){for(var b,d=function(){var b=(l.match(/^.+\n?/)||[])[0];if(!b)return"break";if(c(b))return"break";l=l.replace(b,"");a({type:"tr",children:[]},function(){var c,d=b.trim().split("|");d=d[0]?d.slice(0,f):d.slice(1).slice(0,f),(c=d).push.apply(c,_toConsumableArray(Array(f-d.length).fill(""))),d.forEach(function(b){a({type:"td",children:[]},function(){h(b)})})})};!0&&(b=d(),"break"!==b););})}),!0}}function h(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(b){if(q.url.test(b))return void h(b.replace(q.url,function(b,c,d){return a({type:"a",href:d,value:c,children:[]},function(){h(c)}),""}));if(q.blod.test(b))return void h(b.replace(q.blod,function(b,c){return a({type:"b",children:[]},function(){h(c)}),""}));if(q.italic.test(b))return void h(b.replace(q.italic,function(b,c){return a({type:"i",children:[]},function(){h(c)}),""}));if(q.inlineCode.test(b))return void h(b.replace(q.inlineCode,function(b,c){if(c){a({type:"inlineCode",children:[]},function(){h(c)})}return""}));if(q.video.test(b))return void h(b.replace(q.video,function(a,b,c){return n.children.push({type:"video",src:c,alt:b}),""}));if(q.audio.test(b))return b=b.replace(q.audio,function(a,b,c){return n.children.push({type:"audio",src:c,alt:b}),""}),void h(b);if(q.img.test(b))return void h(b.replace(q.img,function(a,b,c){return n.children.push({type:"img",src:c,alt:b}),""}));if("\n"==b[0])return n.children.push({type:"br"}),void h(b.slice(1));var c=n.children[n.children.length-1];c&&"text"===c.type?c.value+=b[0]:n.children.push({type:"text",value:i(b[0])}),h(b.slice(1))}}function i(a){return a.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function j(){function b(){var e=Math.floor,f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(c){var g=(c.match(/.+\n?/)||[])[0],i=g.match(/\s*/)[0],j=e(i.length/5);if(/^[-+]\s+/.test(g.trim())){var k="+"==g.match(/\s*[-+]/)[0].trim();if(j==f+1){var l={type:"ul",listStyleType:k?"decimal":d[j%d.length],children:[]};return a(l,function(){b(f+1)}),void b(f)}if(j==f){return a({type:"li",children:[]},function(){h(g.replace(/\s*[-+]\s*/,""))}),c=c.slice(g.length),void b(f)}if(j<f)return}var m=n.children[n.children.length-1];a(m,function(){h(g)},{isPush:!1}),c=c.slice(g.length),b(f)}}var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";c="".concat(c,"\n");var d=["disc","circle","square"];b()}function k(){if(!/^\n{1,2}$/.test(l)&&l){if(/Reg.br/.test(l)){var c=l.match(q.br),i=_slicedToArray(c,1),m=i[0];return n.children.push({type:"br"}),b(m),void k()}if(q.head.test(l)){var o=l.match(q.head)||[],p=_slicedToArray(o,3),r=p[0],s=p[1],t=p[2],u={type:"h".concat(s.length),children:[]};return a(u,function(){h(t)}),b(r),void k()}if(q.queto.test(l)){var v=l.match(q.queto),w=_slicedToArray(v,2),x=w[0],y=w[1],z=e(y,"[","]"),A=_slicedToArray(z,2),B=A[0],C=A[1],D={type:"queto",tag:B,children:[]},E=g(C.replace(/^\s*\n/,""));return D.children=E.children,n.children.push(D),n.children.push({type:"br"}),b(x),void k()}if(q.code.test(l)){var F=l.match(q.code),G=_slicedToArray(F,2),H=G[0],I=G[1],J=f(I,"\n").map(function(a){return a.trim()}),K=_slicedToArray(J,2),L=K[0],M=K[1];return n.children.push({type:"code",language:L,value:M}),b(H),void k()}if(q.ul.test(l)){var N=l.match(q.ul),O=_slicedToArray(N,2),P=O[0],Q=O[1];return a(n,function(){j(Q)},{isPush:!1}),n.children.push({type:"br"}),b(P),void k()}if(l.match(/.+\n/)&&/\|.+\|/.test(l.match(/.+\n/)[0].trim())&&d(l))return void k();if(q.hr.test(l)){var R=l.match(q.hr)||[],S=_slicedToArray(R,1),T=S[0];return void 0!==T&&n.children.push({type:"hr",children:[]}),b(T),void k()}if(q.text.test(l)){var U=l.match(q.text)||[""],V=_slicedToArray(U,1),W=V[0];return h(W),b(W),void k()}throw new Error("cannot handle str:".concat(l))}}var l=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";l+="\n\n";var n={children:[],type:"root"};return k(),n}function h(a,b){return b&&b.parentElement&&b.parentElement.insertBefore(a,b),a}function i(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(a){var c=a.nextNode;switch(a.type){case"del":{var d=a.prevNode.__htmlNode;d.parentElement||console.log("delete error::",a),d.parentElement.removeChild(d);break}case"add":{k(c,b,{beforeAppend:function(c){var d=b.childNodes[a.moveTo];if(d)return h(c,d),!0}});break}case"replace":{var e=a.prevNode.__htmlNode,f=document.createDocumentFragment();k(c,f),e.parentElement.replaceChild(f,e);break}case"move":{var g=a.moveTo,j=a.prevNode,l=j.__htmlNode.parentElement;l.childNodes[g]!==j.__htmlNode&&(l.childNodes[g]?h(j.__htmlNode,l.childNodes[g]):l.appendChild(j.__htmlNode));break}case"update":{var m=a.propsChange,n=a.children,o=a.prevNode,p=a.nextNode,q=o.__htmlNode;p.__htmlNode=q,o.__update&&(p.__update=o.__update),m.forEach(function(a){var b=a.key;switch(a.type){case"change":case"add":{var c=p[b];if(o.__update){o.__update(b,p);break}if(q instanceof Text){q.data=c;break}q.setAttribute(b,c);break}case"del":{q.removeAttribute(b);break}}}),n.forEach(function(a){return i(a,q)});break}default:console.error("canot handle type",a,a.type);}}}function j(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===a.type&&(b+=a.value||""),a.children&&a.children.forEach(function(a){b+=j(a)}),b}function k(b,c){var d,e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(b.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(b.src.trim())){d=document.createElement("div"),d.className="audio",d.innerHTML=b.src.replace("http://","//");var f=d.querySelector("iframe");f.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else d=document.createElement(b.type),d.src=b.src,d.alt=b.alt,d.controls="true";break}case"img":{var g=b.src.match(/\.(\d+)x(\d+)\./);if(g){var h=g.slice(1,3),i=_slicedToArray(h,2),l=i[0],m=i[1],n=b.src;d=document.createElement("div"),d.style.cssText=";position: relative; max-width: ".concat(l,"px; overflow: hidden; background: rgb(219, 221, 215);"),d.innerHTML="<div style=\"padding-top: ".concat(100*(m/l),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(n)?"src=\"".concat(n,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(b.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{d=document.createElement(b.type),d.src=b.src,d.alt=b.alt;break}}case"text":{var o=b.value;d=document.createTextNode(o);break}case"br":{d=document.createElement(b.type);break}case"a":{d=document.createElement(b.type),d.href=b.href,d.target="_blank";break}case"code":{d=document.createElement("pre");var p=document.createElement("code");b.__update=function(a,b){switch(a){case"language":{p.className=["highlight",b[a]||""].join(" ");break}case"value":{p.textContent=b[a];break}default:}},b.__update("language",b),b.__update("value",b),d.appendChild(p);break}case"inlineCode":{d=document.createElement("code"),d.className="inlineCode";break}case"h1":{d=document.createElement(b.type);var q=document.createElement("a"),a=j(b);q.href="#".concat(a),q.id=a,d.appendChild(q);break}case"ul":{d=document.createElement(b.type),b.__update=function(a,b){d.style.cssText+=";list-style-type:".concat(b[a],";")},b.__update("listStyleType",b);break}default:d=document.createElement(b.type),b.indent&&(d.style.cssText+=";padding-left: 2em;"),"table"==b.type&&d.setAttribute("border","1");}b.tag&&d.setAttribute("tag",b.tag),b.children&&b.children.forEach(function(a){return k(a,d)});var r=e.beforeAppend&&e.beforeAppend(d);return r||c.appendChild(d),b.__htmlNode=d,d}function l(a){function b(a){"text"==a.type&&(c+=a.value||""),"img"==a.type&&d.push(a.src),a.children&&a.children.forEach(b)}var c="",d=[];return b(a),{text:c,imgs:d}}function m(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=r[a];if(!b){var c=g(a);b=_objectSpread({root:c},l(c)),r[a]=b}return b}function n(a){return new Promise(function(b){if(t[a])return b();var c=function(){t[a]=!0,b()};if(a.endsWith(".js")){var d=document.createElement("script");d.onload=c,d.src=a,document.head.appendChild(d)}else if(a.endsWith(".css")){var e=document.createElement("link");e.onload=c,e.type="text/css",e.rel="stylesheet",e.charset="utf-8",e.href=a,document.head.appendChild(e)}})}function o(a,b){Promise.all(b.asset.map(n)).then(function(){window.hljs&&a&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(a.querySelectorAll("code.highlight")).forEach(function(a){window.hljs.highlightBlock(a)}))})}function p(a){return _objectSpread({asset:[]},a)}var q={get hr(){return /(^-{3,}[^\n]+\n?)/},get code(){return /^`{3}(((?!```)[\s\S])*)`{3}/},get queto(){return /^>(((?!\n\n)[\s\S])*)\n\n/},get head(){return /^\s*(#{1,6})([^\n]*)\n?/},get ul(){return /^([-+]\s+((?!\n\n)[\s\S])*)\n\n/},get url(){return /^\[([^\]]+)\]\(([^)]+)\)/},get inlineCode(){return /^`([^`]*)`/},get br(){return /^\n/},get text(){return /^[^\n]*\n?/},get blod(){return /^\*{3}(((?!\*{3}).)*)\*{3}/},get italic(){return /^\*{2}(((?!\*{2}).)*)\*{2}/},get video(){return /^!{3}\[([^\]]*)\]\(([^)]+)\)/},get audio(){return /^!{2}\[([^\]]*)\]\(([^)]+)\)/},get img(){return /^!\[([^\]]*)\]\(([^)]+)\)/}},r={},t={},u=function(){function a(b,c){_classCallCheck(this,a),this.dom=b,this.config=c,this.prevRoot=null}return _createClass(a,[{key:"update",value:function(a){this.dom.classList.add("markdown");var c=m(a),d=b(this.prevRoot,c.root);this.prevRoot=c.root,i(d,this.dom);var e=p(this.config);e.useHighlight&&o(this.dom,e)}}]),a}();return a.Markdown=u,a.parser=g,a.trans=k,a.codeHighlight=o,a.getParseResult=m,a.markdown=function(a,b,c){a.innerHTML="",a.classList.add("markdown");var d=m(b);k(d.root,a),c=p(c),o(a,c)},a.markdownInfo=function(a){var b=m(a),c=b.root,d=_objectWithoutProperties(b,["root"]);return d},a}({}); | ||
"use strict";function _objectWithoutProperties(g,a){if(null==g)return{};var b,h,i=_objectWithoutPropertiesLoose(g,a);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(g);for(h=0;h<e.length;h++)b=e[h],!(0<=a.indexOf(b))&&Object.prototype.propertyIsEnumerable.call(g,b)&&(i[b]=g[b])}return i}function _objectWithoutPropertiesLoose(g,a){if(null==g)return{};var b,h,i={},e=Object.keys(g);for(h=0;h<e.length;h++)b=e[h],0<=a.indexOf(b)||(i[b]=g[b]);return i}function _classCallCheck(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,a){for(var b,f=0;f<a.length;f++)b=a[f],b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(e,b.key,b)}function _createClass(d,a,b){return a&&_defineProperties(d.prototype,a),b&&_defineProperties(d,b),d}function _slicedToArray(c,a){return _arrayWithHoles(c)||_iterableToArrayLimit(c,a)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(i,a){var b,j=[],c=!0,k=!1;try{for(var l,m=i[Symbol.iterator]();!(c=(l=m.next()).done)&&(j.push(l.value),!(a&&j.length===a));c=!0);}catch(c){k=!0,b=c}finally{try{c||null==m["return"]||m["return"]()}finally{if(k)throw b}}return j}function _arrayWithHoles(b){if(Array.isArray(b))return b}function _objectSpread(e){for(var a=1;a<arguments.length;a++){var f=null==arguments[a]?{}:arguments[a],c=Object.keys(f);"function"==typeof Object.getOwnPropertySymbols&&(c=c.concat(Object.getOwnPropertySymbols(f).filter(function(b){return Object.getOwnPropertyDescriptor(f,b).enumerable}))),c.forEach(function(a){_defineProperty(e,a,f[a])})}return e}function _defineProperty(d,a,b){return a in d?Object.defineProperty(d,a,{value:b,enumerable:!0,configurable:!0,writable:!0}):d[a]=b,d}function _toConsumableArray(b){return _arrayWithoutHoles(b)||_iterableToArray(b)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(b){if(Symbol.iterator in Object(b)||"[object Arguments]"===Object.prototype.toString.call(b))return Array.from(b)}function _arrayWithoutHoles(d){if(Array.isArray(d)){for(var a=0,e=Array(d.length);a<d.length;a++)e[a]=d[a];return e}}var fuckMD=function(s){"use strict";function v(d,a){if(!d)return{type:"add",prevNode:d,nextNode:a};if(!a)return{type:"del",prevNode:d,nextNode:a};if(d.type!==a.type)return{type:"replace",prevNode:d,nextNode:a};var b={type:"update",prevNode:d,nextNode:a,propsChange:[],children:[]},e=c(d,a);if(e.length){var f;(f=b.propsChange).push.apply(f,_toConsumableArray(e))}return(b.children=w(d,a).filter(function(b){return b}),0<b.propsChange.length+b.children.length)?b:(a.__htmlNode=d.__htmlNode,a.__update=d.__update,b)}function w(b,a){var c=b.children,d=void 0===c?[]:c,e=a.children,f=void 0===e?[]:e,g=[],h=[],i=d.filter(function(c){return!!f.some(function(a){return a.type===c.type})||(g.push(v(c,null)),!1)});f.forEach(function(d){i.some(function(a,b){return a.type===d.type&&(i[b]={isDel:!0,ele:a},!0)})}),i.filter(function(b){return!b.isDel}).forEach(function(b){return g.push(v(b,null))});var j=i.filter(function(b){return b.isDel}).map(function(b){return b.ele});return f.forEach(function(b,a){var c=j.some(function(c,d){if(c.type===b.type){j.splice(d,1),j.splice(a>d?a-1:a,0,{used:!0,ele:c}),d!==a&&h.push({type:"move",prevNode:c,nextNode:b,current:d,moveTo:a>d?a+1:a});var e=v(c,b);return h.push(e),!0}return!1});if(!c){j.splice(a,0,{add:!0,item:b});var d=v(null,b);h.push(_objectSpread({},d,{moveTo:a}))}}),g.concat(h,[],[])}function c(){var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},b=Object.keys(f),g=Object.keys(a),h=[];return b.forEach(function(b){return["__htmlNode","__parent","__update","children","type"].includes(b)?void 0:g.includes(b)?void(f[b]!==a[b]&&h.push({type:"change",key:b,prevNode:f,nextNode:a})):void h.push({type:"del",key:b,prevNode:f,nextNode:a})}),g.forEach(function(c){b.includes(c)||h.push({type:"add",key:c,prevNode:f,nextNode:a})}),h}function a(){for(var i,j=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",d=0,k=-1,l=0,m=function(b){return j.slice(d,d+b.length)===b};d<j.length;){if(i=j[d],!l)if(!i.trim()){d+=1;continue}else if(m(b)){k=d,l+=1,d+=b.length;continue}else return[void 0,j];if(m(c)?(l-=1,d+=c.length):m(b)?(l+=1,d+=b.length):d+=1,!l)return[j.slice(k+b.length,d-c.length),j.slice(d)]}return[void 0,j]}function d(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",b=d.indexOf(a);return[d.slice(0,b),d.slice(b+a.length)]}function e(){function q(f,a){var b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},c=b.isPush,d=o;o=f,f.__parent=o,a&&a(),o=d,(void 0===c||c)&&o.children.push(f)}function f(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";k=k.slice(b.length)}function g(c){return[X.head,X.ul,X.code,X.queto].some(function(a){return a.test(c)})}function b(){function a(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,b=d.split("\n")[a].trim();return /^\|.+\|$/.test(b)?b.split("|").slice(1,-1):[]}var b=a(k,0),c=a(k,1),e=b.length;if(0!=e&&b.length==c.length&&c.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return q({type:"table",children:[]},function(){k=k.replace(/(.+)\n?/,function(a,b){return q({type:"thead",children:[]},function(){q({type:"tr",children:[]},function(){b.trim().split("|").slice(1,-1).map(function(a){q({type:"th",children:[]},function(){m(a)})})})}),""}),k=k.replace(/.+\n?/,""),q({type:"tbody",children:[]},function(){for(var a,c=function(){var a=(k.match(/^.+\n?/)||[])[0];return a?g(a)?"break":void(k=k.replace(a,""),q({type:"tr",children:[]},function(){var b,f=a.trim().split("|");f=f[0]?f.slice(0,e):f.slice(1).slice(0,e),(b=f).push.apply(b,_toConsumableArray(Array(e-f.length).fill(""))),f.forEach(function(a){q({type:"td",children:[]},function(){m(a)})})})):"break"};a=c(),"break"!==a;);})}),!0}function m(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(X.url.test(a))return void m(a.replace(X.url,function(a,b,c){return q({type:"a",href:c,value:b,children:[]},function(){m(b)}),""}));if(X.blod.test(a))return void m(a.replace(X.blod,function(a,b){return q({type:"b",children:[]},function(){m(b)}),""}));if(X.italic.test(a))return void m(a.replace(X.italic,function(a,b){return q({type:"i",children:[]},function(){m(b)}),""}));if(X.inlineCode.test(a))return void m(a.replace(X.inlineCode,function(a,b){return b&&q({type:"inlineCode",children:[]},function(){m(b)}),""}));if(X.video.test(a))return void m(a.replace(X.video,function(d,a,b){return o.children.push({type:"video",src:b,alt:a}),""}));if(X.audio.test(a))return a=a.replace(X.audio,function(d,a,b){return o.children.push({type:"audio",src:b,alt:a}),""}),void m(a);if(X.img.test(a))return void m(a.replace(X.img,function(d,a,b){return o.children.push({type:"img",src:b,alt:a}),""}));if("\n"==a[0])return o.children.push({type:"br"}),void m(a.slice(1));var d=o.children[o.children.length-1];d&&"text"===d.type?d.value+=a[0]:o.children.push({type:"text",value:h(a[0])}),m(a.slice(1))}}function h(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function c(){function a(){var c=Math.floor,d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(b){var f=(b.match(/.+\n?/)||[])[0],g=f.match(/\s*/)[0],h=c(g.length/5);if(/^[-+]\s+/.test(f.trim())){var i="+"==f.match(/\s*[-+]/)[0].trim();if(h==d+1){var j={type:"ul",listStyleType:i?"decimal":e[h%e.length],children:[]};return q(j,function(){a(d+1)}),void a(d)}if(h==d)return q({type:"li",children:[]},function(){m(f.replace(/\s*[-+]\s*/,""))}),b=b.slice(f.length),void a(d);if(h<d)return}var k=o.children[o.children.length-1];q(k,function(){m(f)},{isPush:!1}),b=b.slice(f.length),a(d)}}var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";b="".concat(b,"\n");var e=["disc","circle","square"];a()}function j(){if(!/^\n{1,2}$/.test(k)&&k){if(/Reg.br/.test(k)){var g=k.match(X.br),h=_slicedToArray(g,1),i=h[0];return o.children.push({type:"br"}),f(i),void j()}if(X.head.test(k)){var l=k.match(X.head)||[],n=_slicedToArray(l,3),p=n[0],r=n[1],s=n[2],t={type:"h".concat(r.length),children:[]};return q(t,function(){m(s)}),f(p),void j()}if(X.queto.test(k)){var u=k.match(X.queto),v=_slicedToArray(u,2),w=v[0],x=v[1],y=a(x,"[","]"),z=_slicedToArray(y,2),A=z[0],B=z[1],C={type:"queto",tag:A,children:[]},D=e(B.replace(/^\s*\n/,""));return C.children=D.children,o.children.push(C),o.children.push({type:"br"}),f(w),void j()}if(X.code.test(k)){var E=k.match(X.code),F=_slicedToArray(E,2),G=F[0],H=F[1],I=d(H,"\n").map(function(b){return b.trim()}),J=_slicedToArray(I,2),K=J[0],L=J[1];return o.children.push({type:"code",language:K,value:L}),f(G),void j()}if(X.ul.test(k)){var M=k.match(X.ul),N=_slicedToArray(M,2),O=N[0],P=N[1];return q(o,function(){c(P)},{isPush:!1}),o.children.push({type:"br"}),f(O),void j()}if(k.match(/.+\n/)&&/\|.+\|/.test(k.match(/.+\n/)[0].trim())&&b(k))return void j();if(X.hr.test(k)){var Q=k.match(X.hr)||[],R=_slicedToArray(Q,1),S=R[0];return void 0!==S&&o.children.push({type:"hr",children:[]}),f(S),void j()}if(X.text.test(k)){var T=k.match(X.text)||[""],U=_slicedToArray(T,1),V=U[0];return m(V),f(V),void j()}throw new Error("cannot handle str:".concat(k))}}var k=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";k+="\n\n";var o={children:[],type:"root"};return j(),o}function f(c,a){return a&&a.parentElement&&a.parentElement.insertBefore(c,a),c}function b(i){var a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(i){var k=i.nextNode;switch(i.type){case"del":{var c=i.prevNode.__htmlNode;c.parentElement||console.log("delete error::",i),c.parentElement.removeChild(c);break}case"add":{h(k,a,{beforeAppend:function(b){var c=a.childNodes[i.moveTo];if(c)return f(b,c),!0}});break}case"replace":{var d=i.prevNode.__htmlNode,e=document.createDocumentFragment();h(k,e),d.parentElement.replaceChild(e,d);break}case"move":{var r=i.moveTo,g=i.prevNode,j=g.__htmlNode.parentElement;j.childNodes[r]!==g.__htmlNode&&(j.childNodes[r]?f(g.__htmlNode,j.childNodes[r]):j.appendChild(g.__htmlNode));break}case"update":{var l=i.propsChange,m=i.children,n=i.prevNode,o=i.nextNode,p=n.__htmlNode;o.__htmlNode=p,n.__update&&(o.__update=n.__update),l.forEach(function(d){var a=d.key;switch(d.type){case"change":case"add":{var b=o[a];if(n.__update){n.__update(a,o);break}if(p instanceof Text){p.data=b;break}p.setAttribute(a,b);break}case"del":{p.removeAttribute(a);break}}}),m.forEach(function(c){return b(c,p)});break}default:console.error("canot handle type",i,i.type);}}}function g(c){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===c.type&&(d+=c.value||""),c.children&&c.children.forEach(function(b){d+=g(b)}),d}function h(j,b){var c,k=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(j.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(j.src.trim())){c=document.createElement("div"),c.className="audio",c.innerHTML=j.src.replace("http://","//");var e=c.querySelector("iframe");e.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else c=document.createElement(j.type),c.src=j.src,c.alt=j.alt,c.controls="true";break}case"img":{var f=j.src.match(/\.(\d+)x(\d+)\./);if(f){var s=f.slice(1,3),t=_slicedToArray(s,2),i=t[0],l=t[1],m=j.src;c=document.createElement("div"),c.style.cssText=";position: relative; max-width: ".concat(i,"px; overflow: hidden; background: rgb(219, 221, 215);"),c.innerHTML="<div style=\"padding-top: ".concat(100*(l/i),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(m)?"src=\"".concat(m,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(j.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{c=document.createElement(j.type),c.src=j.src,c.alt=j.alt;break}}case"text":{var n=j.value;c=document.createTextNode(n);break}case"br":{c=document.createElement(j.type);break}case"a":{c=document.createElement(j.type),c.href=j.href,c.target="_blank";break}case"code":{c=document.createElement("pre");var o=document.createElement("code");j.__update=function(c,a){switch(c){case"language":{o.className=["highlight",a[c]||""].join(" ");break}case"value":{o.textContent=a[c];break}default:}},j.__update("language",j),j.__update("value",j),c.appendChild(o);break}case"inlineCode":{c=document.createElement("code"),c.className="inlineCode";break}case"h1":{c=document.createElement(j.type);var p=document.createElement("a"),q=g(j);p.href="#".concat(q),p.id=q,c.appendChild(p);break}case"ul":{c=document.createElement(j.type),j.__update=function(d,a){c.style.cssText+=";list-style-type:".concat(a[d],";")},j.__update("listStyleType",j);break}default:c=document.createElement(j.type),j.indent&&(c.style.cssText+=";padding-left: 2em;"),"table"==j.type&&c.setAttribute("border","1");}j.tag&&c.setAttribute("tag",j.tag),j.children&&j.children.forEach(function(b){return h(b,c)});var a=k.beforeAppend&&k.beforeAppend(c);return a||b.appendChild(c),j.__htmlNode=c,c}function i(e){function f(c){"text"==c.type&&(b+=c.value||""),"img"==c.type&&g.push(c.src),c.children&&c.children.forEach(f)}var b="",g=[];return f(e),{text:b,imgs:g}}function j(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=n[d];if(!a){var f=e(d);a=_objectSpread({root:f},i(f)),n[d]=a}return a}function k(f){return new Promise(function(a){if(o[f])return a();var b=function(){o[f]=!0,a()};if(f.endsWith(".js")){var c=document.createElement("script");c.onload=b,c.src=f,document.head.appendChild(c)}else if(f.endsWith(".css")){var d=document.createElement("link");d.onload=b,d.type="text/css",d.rel="stylesheet",d.charset="utf-8",d.href=f,document.head.appendChild(d)}})}function l(c,a){Promise.all(a.asset.map(k)).then(function(){window.hljs&&c&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(c.querySelectorAll("code.highlight")).forEach(function(b){window.hljs.highlightBlock(b)}))})}function m(b){return _objectSpread({asset:[]},b)}var X={get hr(){return /(^-{3,}[^\n]+\n?)/},get code(){return /^`{3}(((?!```)[\s\S])*)`{3}/},get queto(){return /^>(((?!\n\n)[\s\S])*)\n\n/},get head(){return /^\s*(#{1,6})([^\n]*)\n?/},get ul(){return /^([-+]\s+((?!\n\n)[\s\S])*)\n\n/},get url(){return /^\[([^\]]+)\]\(([^)]+)\)/},get inlineCode(){return /^`([^`]*)`/},get br(){return /^\n/},get text(){return /^[^\n]*\n?/},get blod(){return /^\*{3}(((?!\*{3}).)*)\*{3}/},get italic(){return /^\*{2}(((?!\*{2}).)*)\*{2}/},get video(){return /^!{3}\[([^\]]*)\]\(([^)]+)\)/},get audio(){return /^!{2}\[([^\]]*)\]\(([^)]+)\)/},get img(){return /^!\[([^\]]*)\]\(([^)]+)\)/}},n={},o={},p=function(){function d(a,b){_classCallCheck(this,d),this.dom=a,this.config=b,this.prevRoot=null}return _createClass(d,[{key:"update",value:function(f){this.dom.classList.add("markdown");var a=j(f),c=v(this.prevRoot,a.root);this.prevRoot=a.root,b(c,this.dom);var d=m(this.config);d.useHighlight&&l(this.dom,d)}}]),d}();return s.Markdown=p,s.parser=e,s.trans=h,s.codeHighlight=l,s.getParseResult=j,s.markdown=function(e,a,b){e.innerHTML="",e.classList.add("markdown");var f=j(a);h(f.root,e),b=m(b),l(e,b)},s.markdownInfo=function(e){var a=j(e),b=a.root,c=_objectWithoutProperties(a,["root"]);return c},s}({}); |
{ | ||
"name": "lys-markdown-parser", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"description": "js markdown parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -72,2 +72,3 @@ /** | ||
data-lazy-img="${node.src}" | ||
data-src="${node.src}" | ||
style="position: absolute; width: 100%; height: 100%; top: 0;" /> | ||
@@ -74,0 +75,0 @@ </div>` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303062
17
3953