lys-markdown-parser
Advanced tools
Comparing version 3.10.0 to 3.11.0
@@ -1,1 +0,1 @@ | ||
"use strict";function _objectWithoutProperties(b,c){if(null==b)return{};var d,e,i=_objectWithoutPropertiesLoose(b,c);if(Object.getOwnPropertySymbols){var h=Object.getOwnPropertySymbols(b);for(e=0;e<h.length;e++)d=h[e],!(0<=c.indexOf(d))&&Object.prototype.propertyIsEnumerable.call(b,d)&&(i[d]=b[d])}return i}function _objectWithoutPropertiesLoose(b,c){if(null==b)return{};var d,e,i={},h=Object.keys(b);for(e=0;e<h.length;e++)d=h[e],0<=c.indexOf(d)||(i[d]=b[d]);return i}function _classCallCheck(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(b,c){for(var d,f=0;f<c.length;f++)d=c[f],d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(b,d.key,d)}function _createClass(b,c,d){return c&&_defineProperties(b.prototype,c),d&&_defineProperties(b,d),b}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(f,c){var d,g=[],a=!0,k=!1;try{for(var l,m=f[Symbol.iterator]();!(a=(l=m.next()).done)&&(g.push(l.value),!(c&&g.length===c));a=!0);}catch(a){k=!0,d=a}finally{try{a||null==m["return"]||m["return"]()}finally{if(k)throw d}}return g}function _arrayWithHoles(b){if(Array.isArray(b))return b}function _objectSpread(c){for(var a=1;a<arguments.length;a++){var e=null==arguments[a]?{}:arguments[a],f=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(f=f.concat(Object.getOwnPropertySymbols(e).filter(function(b){return Object.getOwnPropertyDescriptor(e,b).enumerable}))),f.forEach(function(a){_defineProperty(c,a,e[a])})}return c}function _defineProperty(b,c,d){return c in b?Object.defineProperty(b,c,{value:d,enumerable:!0,configurable:!0,writable:!0}):b[c]=d,b}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(c){if(Array.isArray(c)){for(var a=0,e=Array(c.length);a<c.length;a++)e[a]=c[a];return e}}var fuckMD=function(i){"use strict";function o(b,c){if(!b)return{type:"add",prevNode:b,nextNode:c};if(!c)return{type:"del",prevNode:b,nextNode:c};if(b.type!==c.type)return{type:"replace",prevNode:b,nextNode:c};var d={type:"update",prevNode:b,nextNode:c,propsChange:[],children:[]},e=q(b,c);if(e.length){var f;(f=d.propsChange).push.apply(f,_toConsumableArray(e))}return(d.children=p(b,c).filter(function(b){return b}),0<d.propsChange.length+d.children.length)?d:(c.__htmlNode=b.__htmlNode,c.__update=b.__update,d)}function p(e,c){var a=e.children,b=void 0===a?[]:a,f=c.children,g=void 0===f?[]:f,d=[],h=[],i=b.filter(function(c){return!!g.some(function(a){return a.type===c.type})||(d.push(o(c,null)),!1)});g.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(a){return d.push(o(a,null))});var j=i.filter(function(b){return b.isDel}).map(function(b){return b.ele});return g.forEach(function(b,c){var d=j.some(function(d,e){if(d.type===b.type){j.splice(e,1),j.splice(c>e?c-1:c,0,{used:!0,ele:d}),e!==c&&h.push({type:"move",prevNode:d,nextNode:b,current:e,moveTo:c>e?c+1:c});var f=o(d,b);return h.push(f),!0}return!1});if(!d){j.splice(c,0,{add:!0,item:b});var e=o(null,b);h.push(_objectSpread({},e,{moveTo:c}))}}),d.concat(h,[],[])}function q(){var g=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=Object.keys(g),b=Object.keys(e),c=[];return d.forEach(function(d){return["__htmlNode","__parent","__update","children","type"].includes(d)?void 0:b.includes(d)?void(g[d]!==e[d]&&c.push({type:"change",key:d,prevNode:g,nextNode:e})):void c.push({type:"del",key:d,prevNode:g,nextNode:e})}),b.forEach(function(a){d.includes(a)||c.push({type:"add",key:a,prevNode:g,nextNode:e})}),c}function s(){for(var b,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",d=0,k=-1,l=0,m=function(b){return c.slice(d,d+b.length)===b};d<c.length;){if(b=c[d],!l)if(!b.trim()){d+=1;continue}else if(m(e)){k=d,l+=1,d+=e.length;continue}else return[void 0,c];if(m(f)?(l-=1,d+=f.length):m(e)?(l+=1,d+=e.length):d+=1,!l)return[c.slice(k+e.length,d-f.length),c.slice(d)]}return[void 0,c]}function b(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",d=b.indexOf(c);return[b.slice(0,d),b.slice(d+c.length)]}function x(){function r(f,a){var b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},c=b.isPush,d=p;p=f,f.__parent=p,a&&a(),p=d,(void 0===c||c)&&p.children.push(f)}function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";o=o.slice(b.length)}function c(c){return[J.head,J.ul,J.code,J.queto].some(function(a){return a.test(c)})}function n(){function d(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,d=b.split("\n")[c].trim();return /^\|.+\|$/.test(d)?d.split("|").slice(1,-1):[]}var b=d(o,0),e=d(o,1),a=b.length;if(0!=a&&b.length==e.length&&e.every(function(b){return /^-+$/.test(b.replace(/\s/g,""))}))return r({type:"table",children:[]},function(){o=o.replace(/(.+)\n?/,function(a,b){return r({type:"thead",children:[]},function(){r({type:"tr",children:[]},function(){b.trim().split("|").slice(1,-1).map(function(a){r({type:"th",children:[]},function(){k(a)})})})}),""}),o=o.replace(/.+\n?/,""),r({type:"tbody",children:[]},function(){for(var d,e=function d(){var d=(o.match(/^.+\n?/)||[])[0];return d?c(d)?"break":void(o=o.replace(d,""),r({type:"tr",children:[]},function(){var b,e=d.trim().split("|");e=e[0]?e.slice(0,a):e.slice(1).slice(0,a),(b=e).push.apply(b,_toConsumableArray(Array(a-e.length).fill(""))),e.forEach(function(a){r({type:"td",children:[]},function(){k(a)})})})):"break"};d=e(),"break"!==d;);})}),!0}function k(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(J.url.test(a))return void k(a.replace(J.url,function(c,d,a){return r({type:"a",href:a,value:d,children:[]},function(){k(d)}),""}));if(J.blod.test(a))return void k(a.replace(J.blod,function(a,b){return r({type:"b",children:[]},function(){k(b)}),""}));if(J.italic.test(a))return void k(a.replace(J.italic,function(a,b){return r({type:"i",children:[]},function(){k(b)}),""}));if(J.inlineCode.test(a))return void k(a.replace(J.inlineCode,function(a,b){return b&&r({type:"inlineCode",children:[]},function(){k(b)}),""}));if(J.video.test(a))return void k(a.replace(J.video,function(b,c,d){return p.children.push({type:"video",src:d,alt:c}),""}));if(J.audio.test(a))return a=a.replace(J.audio,function(b,c,d){return p.children.push({type:"audio",src:d,alt:c}),""}),void k(a);if(J.img.test(a))return void k(a.replace(J.img,function(b,c,d){return p.children.push({type:"img",src:d,alt:c}),""}));if("\n"==a[0])return p.children.push({type:"br"}),void k(a.slice(1));var b=p.children[p.children.length-1];b&&"text"===b.type?b.value+=a[0]:p.children.push({type:"text",value:e(a[0])}),k(a.slice(1))}}function e(b){return b.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function d(){function g(){var a=Math.floor,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(j){var e=(j.match(/.+\n?/)||[])[0],d=e.match(/\s*/)[0],k=a(d.length/5);if(/^[-+]\s+/.test(e.trim())){var h="+"==e.match(/\s*[-+]/)[0].trim();if(k==c+1){var i={type:"ul",listStyleType:h?"decimal":b[k%b.length],children:[]};return r(i,function(){g(c+1)}),void g(c)}if(k==c)return r({type:"li",children:[]},function(){c(e.replace(/\s*[-+]\s*/,""))}),j=j.slice(e.length),void g(c);if(k<c)return}var l=p.children[p.children.length-1];r(l,function(){c(e)},{isPush:!1}),j=j.slice(e.length),g(c)}}var j=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";j="".concat(j,"\n");var b=["disc","circle","square"];g()}function g(){if(!/^\n{1,2}$/.test(o)&&o){if(/Reg.br/.test(o)){var c=o.match(J.br),e=_slicedToArray(c,1),f=e[0];return p.children.push({type:"br"}),a(f),void g()}if(J.head.test(o)){var h=o.match(J.head)||[],i=_slicedToArray(h,3),j=i[0],l=i[1],m=i[2],q={type:"h".concat(l.length),children:[]};return r(q,function(){k(m)}),a(j),void g()}if(J.queto.test(o)){var t=o.match(J.queto),K=_slicedToArray(t,2),L=K[0],M=K[1],v=s(M,"[","]"),D=_slicedToArray(v,2),E=D[0],N=D[1],O={type:"queto",tag:E,children:[]},P=x(N.replace(/^\s*\n/,""));return O.children=P.children,p.children.push(O),p.children.push({type:"br"}),a(L),void g()}if(J.code.test(o)){var w=o.match(J.code),Q=_slicedToArray(w,2),R=Q[0],S=Q[1],T=b(S,"\n").map(function(b){return b.trim()}),u=_slicedToArray(T,2),W=u[0],y=u[1];return p.children.push({type:"code",language:W,value:y}),a(R),void g()}if(J.ul.test(o)){var U=o.match(J.ul),z=_slicedToArray(U,2),A=z[0],B=z[1];return r(p,function(){d(B)},{isPush:!1}),p.children.push({type:"br"}),a(A),void g()}if(o.match(/.+\n/)&&/\|.+\|/.test(o.match(/.+\n/)[0].trim())&&n(o))return void g();if(J.hr.test(o)){var C=o.match(J.hr)||[],V=_slicedToArray(C,1),X=V[0];return void 0!==X&&p.children.push({type:"hr",children:[]}),a(X),void g()}if(J.text.test(o)){var F=o.match(J.text)||[""],G=_slicedToArray(F,1),H=G[0];return k(H),a(H),void g()}throw new Error("cannot handle str:".concat(o))}}var o=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";o+="\n\n";var p={children:[],type:"root"};return g(),p}function a(c,a){return a&&a.parentElement&&a.parentElement.insertBefore(c,a),c}function j(o){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(o){var e=o.nextNode;switch(o.type){case"del":{var f=o.prevNode.__htmlNode;f.parentElement||console.log("delete error::",o),f.parentElement.removeChild(f);break}case"add":{r(e,d,{beforeAppend:function(e){var b=d.childNodes[o.moveTo];if(b)return a(e,b),!0}});break}case"replace":{var b=o.prevNode.__htmlNode,c=document.createDocumentFragment();r(e,c),b.parentElement.replaceChild(c,b);break}case"move":{var k=o.moveTo,l=o.prevNode,g=l.__htmlNode.parentElement;g.childNodes[k]!==l.__htmlNode&&(g.childNodes[k]?a(l.__htmlNode,g.childNodes[k]):g.appendChild(l.__htmlNode));break}case"update":{var h=o.propsChange,p=o.children,i=o.prevNode,q=o.nextNode,m=i.__htmlNode;q.__htmlNode=m,i.__update&&(q.__update=i.__update),h.forEach(function(a){var b=a.key;switch(a.type){case"change":case"add":{var c=q[b];if(i.__update){i.__update(b,q);break}if(m instanceof Text){m.data=c;break}m.setAttribute(b,c);break}case"del":{m.removeAttribute(b);break}}}),p.forEach(function(a){return j(a,m)});break}default:console.error("canot handle type",o,o.type);}}}function t(a){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===a.type&&(c+=a.value||""),a.children&&a.children.forEach(function(a){c+=t(a)}),c}function r(c,e){var f,b=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(c.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(c.src.trim())){f=document.createElement("div"),f.className="audio",f.innerHTML=c.src.replace("http://","//");var k=f.querySelector("iframe");k.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else f=document.createElement(c.type),f.src=c.src,f.alt=c.alt,f.controls="true";break}case"img":{var m=c.src.match(/\.(\d+)x(\d+)\./);if(m){var n=m.slice(1,3),g=_slicedToArray(n,2),l=g[0],a=g[1],i=c.src;f=document.createElement("div"),f.style.cssText=";position: relative; max-width: ".concat(l,"px; overflow: hidden; background: rgb(219, 221, 215);"),f.innerHTML="<div style=\"padding-top: ".concat(100*(a/l),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(i)?"src=\"".concat(i,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(c.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{f=document.createElement(c.type),f.src=c.src,f.alt=c.alt;break}}case"text":{var o=c.value;f=document.createTextNode(o);break}case"br":{f=document.createElement(c.type);break}case"a":{f=document.createElement(c.type),f.href=c.href,f.target="_blank";break}case"code":{f=document.createElement("pre");var j=document.createElement("code");c.__update=function(c,a){switch(c){case"language":{j.className=["highlight",a[c]||""].join(" ");break}case"value":{j.textContent=a[c];break}default:}},c.__update("language",c),c.__update("value",c),f.appendChild(j);break}case"inlineCode":{f=document.createElement("code"),f.className="inlineCode";break}case"h1":{f=document.createElement(c.type);var p=document.createElement("a"),q=t(c);p.href="#".concat(q),p.id=q,f.appendChild(p);break}case"ul":{f=document.createElement(c.type),c.__update=function(a,b){f.style.cssText+=";list-style-type:".concat(b[a],";")},c.__update("listStyleType",c);break}default:f=document.createElement(c.type),c.indent&&(f.style.cssText+=";padding-left: 2em;"),"table"==c.type&&f.setAttribute("border","1");}c.tag&&f.setAttribute("tag",c.tag),c.children&&c.children.forEach(function(b){return r(b,f)});var d=b.beforeAppend&&b.beforeAppend(f);return d||e.appendChild(f),c.__htmlNode=f,f}function u(b){function e(b){"text"==b.type&&(c+=b.value||""),"img"==b.type&&g.push(b.src),b.children&&b.children.forEach(e)}var c="",g=[];return e(b),{text:c,imgs:g}}function f(){var d=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=c[d];if(!a){var e=x(d);a=_objectSpread({root:e},u(e)),c[d]=a}return a}function e(f){return new Promise(function(a){if(g[f])return a();var b=function(){g[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 k(c,a){Promise.all(a.asset.map(e)).then(function(){window.hljs&&c&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(c.querySelectorAll("code.highlight")).forEach(function(b){window.hljs.highlightBlock(b)}))})}function l(b){return _objectSpread({asset:[]},b)}var J={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 /^!\[([^\]]*)\]\(([^)]+)\)/}},c={},g={},d=function(){function c(b,d){_classCallCheck(this,c),this.dom=b,this.config=d,this.prevRoot=null}return _createClass(c,[{key:"update",value:function(c){this.dom.classList.add("markdown");var e=f(c),a=o(this.prevRoot,e.root);this.prevRoot=e.root,j(a,this.dom);var d=l(this.config);d.useHighlight&&k(this.dom,d)}}]),c}();return i.Markdown=d,i.parser=x,i.trans=r,i.codeHighlight=k,i.getParseResult=f,i.markdown=function(b,a,d){b.innerHTML="",b.classList.add("markdown");var g=f(a);r(g.root,b),d=l(d),k(b,d)},i.markdownInfo=function(c){var d=f(c),a=d.root,e=_objectWithoutProperties(d,["root"]);return e},i}({}); | ||
"use strict";function _objectWithoutProperties(c,d){if(null==c)return{};var a,f,i=_objectWithoutPropertiesLoose(c,d);if(Object.getOwnPropertySymbols){var h=Object.getOwnPropertySymbols(c);for(f=0;f<h.length;f++)a=h[f],!(0<=d.indexOf(a))&&Object.prototype.propertyIsEnumerable.call(c,a)&&(i[a]=c[a])}return i}function _objectWithoutPropertiesLoose(c,d){if(null==c)return{};var a,f,i={},h=Object.keys(c);for(f=0;f<h.length;f++)a=h[f],0<=d.indexOf(a)||(i[a]=c[a]);return i}function _classCallCheck(c,a){if(!(c instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(c,d){for(var a,e=0;e<d.length;e++)a=d[e],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(c,a.key,a)}function _createClass(c,d,a){return d&&_defineProperties(c.prototype,d),a&&_defineProperties(c,a),c}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(c,a){var b,g=[],e=!0,h=!1;try{for(var i,j=c[Symbol.iterator]();!(e=(i=j.next()).done)&&(g.push(i.value),!(a&&g.length===a));e=!0);}catch(c){h=!0,b=c}finally{try{e||null==j["return"]||j["return"]()}finally{if(h)throw b}}return g}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _objectSpread(c){for(var a=1;a<arguments.length;a++){var e=null==arguments[a]?{}:arguments[a],f=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(f=f.concat(Object.getOwnPropertySymbols(e).filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),f.forEach(function(a){_defineProperty(c,a,e[a])})}return c}function _defineProperty(c,d,a){return d in c?Object.defineProperty(c,d,{value:a,enumerable:!0,configurable:!0,writable:!0}):c[d]=a,c}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(c){if(Array.isArray(c)){for(var a=0,d=Array(c.length);a<c.length;a++)d[a]=c[a];return d}}var fuckMD=function(a){"use strict";function u(e,f){if(!e)return{type:"add",prevNode:e,nextNode:f};if(!f)return{type:"del",prevNode:e,nextNode:f};if(e.type!==f.type)return{type:"replace",prevNode:e,nextNode:f};var a={type:"update",prevNode:e,nextNode:f,propsChange:[],children:[]},b=g(e,f);if(b.length){var c;(c=a.propsChange).push.apply(c,_toConsumableArray(b))}return(a.children=h(e,f).filter(function(a){return a}),0<a.propsChange.length+a.children.length)?a:(f.__htmlNode=e.__htmlNode,f.__update=e.__update,a)}function h(h,d){var i=h.children,e=void 0===i?[]:i,c=d.children,l=void 0===c?[]:c,j=[],m=[],a=e.filter(function(c){return!!l.some(function(a){return a.type===c.type})||(j.push(u(c,null)),!1)});l.forEach(function(b){a.some(function(e,c){return e.type===b.type&&(a[c]={isDel:!0,ele:e},!0)})}),a.filter(function(a){return!a.isDel}).forEach(function(b){return j.push(u(b,null))});var g=a.filter(function(a){return a.isDel}).map(function(a){return a.ele});return l.forEach(function(e,f){var a=g.some(function(a,b){if(a.type===e.type){g.splice(b,1),g.splice(f>b?f-1:f,0,{used:!0,ele:a}),b!==f&&m.push({type:"move",prevNode:a,nextNode:e,current:b,moveTo:f>b?f+1:f});var c=u(a,e);return m.push(c),!0}return!1});if(!a){g.splice(f,0,{add:!0,item:e});var b=u(null,e);m.push(_objectSpread({},b,{moveTo:f}))}}),j.concat(m,[],[])}function g(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},f=Object.keys(c),g=Object.keys(d),e=[];return f.forEach(function(a){return["__htmlNode","__parent","__update","children","type"].includes(a)?void 0:g.includes(a)?void(c[a]!==d[a]&&e.push({type:"change",key:a,prevNode:c,nextNode:d})):void e.push({type:"del",key:a,prevNode:c,nextNode:d})}),g.forEach(function(a){f.includes(a)||e.push({type:"add",key:a,prevNode:c,nextNode:d})}),e}function c(){for(var a,f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"[",g=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"]",c=0,h=-1,i=0,j=function(a){return f.slice(c,c+a.length)===a};c<f.length;){if(a=f[c],!i)if(!a.trim()){c+=1;continue}else if(j(d)){h=c,i+=1,c+=d.length;continue}else return[void 0,f];if(j(g)?(i-=1,c+=g.length):j(d)?(i+=1,c+=d.length):c+=1,!i)return[f.slice(h+d.length,c-g.length),f.slice(c)]}return[void 0,f]}function i(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",a=c.indexOf(d);return[c.slice(0,a),c.slice(a+d.length)]}function n(){function q(c,d){var e=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},f=e.isPush,a=p;p=c,c.__parent=p,d&&d(),p=a,(void 0===f||f)&&p.children.push(c)}function o(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";e=e.slice(a.length)}function d(c){return[G.head,G.ul,G.code,G.queto].some(function(a){return a.test(c)})}function b(){function g(){var c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,a=c.split("\n")[d].trim();return /^\|.+\|$/.test(a)?a.split("|").slice(1,-1):[]}var a=g(e,0),c=g(e,1),h=a.length;if(0!=h&&a.length==c.length&&c.every(function(a){return /^-+$/.test(a.replace(/\s/g,""))}))return q({type:"table",children:[]},function(){e=e.replace(/(.+)\n?/,function(a,b){return q({type:"thead",children:[]},function(){q({type:"tr",children:[]},function(){b.trim().split("|").slice(1,-1).map(function(b){q({type:"th",children:[]},function(){f(b)})})})}),""}),e=e.replace(/.+\n?/,""),q({type:"tbody",children:[]},function(){for(var a,b=function b(){var b=(e.match(/^.+\n?/)||[])[0];return b?d(b)?"break":void(e=e.replace(b,""),q({type:"tr",children:[]},function(){var c,d=b.trim().split("|");d=d[0]?d.slice(0,h):d.slice(1).slice(0,h),(c=d).push.apply(c,_toConsumableArray(Array(h-d.length).fill(""))),d.forEach(function(b){q({type:"td",children:[]},function(){f(b)})})})):"break"};a=b(),"break"!==a;);})}),!0}function f(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if(a){if(G.url.test(a))return void f(a.replace(G.url,function(d,a,b){return q({type:"a",href:b,value:a,children:[]},function(){f(a)}),""}));if(G.blod.test(a))return void f(a.replace(G.blod,function(a,b){return q({type:"b",children:[]},function(){f(b)}),""}));if(G.italic.test(a))return void f(a.replace(G.italic,function(a,b){return q({type:"i",children:[]},function(){f(b)}),""}));if(G.inlineCode.test(a))return void f(a.replace(G.inlineCode,function(a,b){return b&&q({type:"inlineCode",children:[]},function(){f(b)}),""}));if(G.video.test(a))return void f(a.replace(G.video,function(c,d,a){return p.children.push({type:"video",src:a,alt:d}),""}));if(G.audio.test(a))return a=a.replace(G.audio,function(c,d,a){return p.children.push({type:"audio",src:a,alt:d}),""}),void f(a);if(G.img.test(a))return void f(a.replace(G.img,function(c,d,a){return p.children.push({type:"img",src:a,alt:d}),""}));if("\n"==a[0])return p.children.push({type:"br"}),void f(a.slice(1));var d=p.children[p.children.length-1];d&&"text"===d.type?d.value+=a[0]:p.children.push({type:"text",value:g(a[0])}),f(a.slice(1))}}function g(a){return a.replace(/>/g,">").replace(/\\#/g,"#").replace(/\\`/g,"`").replace(/\\-/g,"-").replace(/\\\*/g,"*")}function a(){function i(){var b=Math.floor,l=0<arguments.length&&void 0!==arguments[0]?arguments[0]:-1;if(f){var g=(f.match(/.+\n?/)||[])[0],j=g.match(/\s*/)[0],c=b(j.length/5);if(/^[-+]\s+/.test(g.trim())){var e="+"==g.match(/\s*[-+]/)[0].trim();if(c==l+1){var d={type:"ul",listStyleType:e?"decimal":a[c%a.length],children:[]};return q(d,function(){i(l+1)}),void i(l)}if(c==l)return q({type:"li",children:[]},function(){l(g.replace(/\s*[-+]\s*/,""))}),f=f.slice(g.length),void i(l);if(c<l)return}var k=p.children[p.children.length-1];q(k,function(){l(g)},{isPush:!1}),f=f.slice(g.length),i(l)}}var f=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";f="".concat(f,"\n");var a=["disc","circle","square"];i()}function h(){if(!/^\n{1,2}$/.test(e)&&e){if(/Reg.br/.test(e)){var l=e.match(G.br),r=_slicedToArray(l,1),d=r[0];return p.children.push({type:"br"}),o(d),void h()}if(G.head.test(e)){var s=e.match(G.head)||[],g=_slicedToArray(s,3),k=g[0],m=g[1],x=g[2],j={type:"h".concat(m.length),children:[]};return q(j,function(){f(x)}),o(k),void h()}if(G.queto.test(e)){var H=e.match(G.queto),I=_slicedToArray(H,2),J=I[0],t=I[1],K=c(t,"[","]"),L=_slicedToArray(K,2),M=L[0],v=L[1],D={type:"queto",tag:M,children:[]},E=n(v.replace(/^\s*\n/,""));return D.children=E.children,p.children.push(D),p.children.push({type:"br"}),o(J),void h()}if(G.code.test(e)){var N=e.match(G.code),O=_slicedToArray(N,2),P=O[0],w=O[1],Q=i(w,"\n").map(function(a){return a.trim()}),R=_slicedToArray(Q,2),S=R[0],T=R[1];return p.children.push({type:"code",language:S,value:T}),o(P),void h()}if(G.ul.test(e)){var u=e.match(G.ul),W=_slicedToArray(u,2),y=W[0],U=W[1];return q(p,function(){a(U)},{isPush:!1}),p.children.push({type:"br"}),o(y),void h()}if(e.match(/.+\n/)&&/\|.+\|/.test(e.match(/.+\n/)[0].trim())&&b(e))return void h();if(G.hr.test(e)){var z=e.match(G.hr)||[],A=_slicedToArray(z,1),B=A[0];return void 0!==B&&p.children.push({type:"hr",children:[]}),o(B),void h()}if(G.text.test(e)){var C=e.match(G.text)||[""],V=_slicedToArray(C,1),X=V[0];return f(X),o(X),void h()}throw new Error("cannot handle str:".concat(e))}}var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";e+="\n\n";var p={children:[],type:"root"};return h(),p}function q(c,a){return a&&a.parentElement&&a.parentElement.insertBefore(c,a),c}function s(b){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.body;if(b){var a=b.nextNode;switch(b.type){case"del":{var j=b.prevNode.__htmlNode;j.parentElement||console.log("delete error::",b),j.parentElement.removeChild(j);break}case"add":{v(a,d,{beforeAppend:function(a){var e=d.childNodes[b.moveTo];if(e)return q(a,e),!0}});break}case"replace":{var m=b.prevNode.__htmlNode,e=document.createDocumentFragment();v(a,e),m.parentElement.replaceChild(e,m);break}case"move":{var f=b.moveTo,o=b.prevNode,c=o.__htmlNode.parentElement;c.childNodes[f]!==o.__htmlNode&&(c.childNodes[f]?q(o.__htmlNode,c.childNodes[f]):c.appendChild(o.__htmlNode));break}case"update":{var k=b.propsChange,l=b.children,g=b.prevNode,h=b.nextNode,n=g.__htmlNode;h.__htmlNode=n,g.__update&&(h.__update=g.__update),k.forEach(function(b){var c=b.key;switch(b.type){case"change":case"add":{var d=h[c];if(g.__update){g.__update(c,h);break}if(n instanceof Text){n.data=d;break}n.setAttribute(c,d);break}case"del":{n.removeAttribute(c);break}}}),l.forEach(function(b){return s(b,n)});break}default:console.error("canot handle type",b,b.type);}}}function b(d){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return"text"===d.type&&(e+=d.value||""),d.children&&d.children.forEach(function(c){e+=b(c)}),e}function v(e,d){var f,m=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};switch(e.type){case"audio":case"video":{if(/^<iframe(\s*.+)*><\/iframe>$/.test(e.src.trim())){f=document.createElement("div"),f.className="audio",f.innerHTML=e.src.replace("http://","//");var c=f.querySelector("iframe");c.style.cssText+=";max-width: 100%; max-height: 60vw; overflow: hidden;"}else f=document.createElement(e.type),f.src=e.src,f.alt=e.alt,f.controls="true";break}case"img":{var j=e.src.match(/\.(\d+)x(\d+)\./);if(j){var o=j.slice(1,3),k=_slicedToArray(o,2),q=k[0],n=k[1],g=e.src;f=document.createElement("div"),f.style.cssText=";position: relative; max-width: ".concat(q,"px; overflow: hidden; background: rgb(219, 221, 215);"),f.innerHTML="<div style=\"padding-top: ".concat(100*(n/q),"%;\">\n <img ").concat(LY.lazyLoad.caches.includes(g)?"src=\"".concat(g,"\" data-img-cache=\"true\""):"","\n class=\"lazy-load-img img-loading\"\n data-lazy-img=\"").concat(e.src,"\"\n style=\"position: absolute; width: 100%; height: 100%; top: 0;\" />\n </div>");break}else{f=document.createElement(e.type),f.src=e.src,f.alt=e.alt;break}}case"text":{var l=e.value;f=document.createTextNode(l);break}case"br":{f=document.createElement(e.type);break}case"a":{f=document.createElement(e.type),f.href=e.href,f.target="_blank";break}case"code":{f=document.createElement("pre");var r=document.createElement("code");e.__update=function(c,a){switch(c){case"language":{r.className=["highlight",a[c]||""].join(" ");break}case"value":{r.textContent=a[c];break}default:}},e.__update("language",e),e.__update("value",e),f.appendChild(r);break}case"inlineCode":{f=document.createElement("code"),f.className="inlineCode";break}case"h1":{f=document.createElement(e.type);var a=document.createElement("a"),i=b(e);a.href="#".concat(i),a.id=i,f.appendChild(a);break}case"ul":{f=document.createElement(e.type),e.__update=function(a,b){f.style.cssText+=";list-style-type:".concat(b[a],";")},e.__update("listStyleType",e);break}default:f=document.createElement(e.type),e.indent&&(f.style.cssText+=";padding-left: 2em;"),"table"==e.type&&f.setAttribute("border","1");}e.tag&&f.setAttribute("tag",e.tag),e.children&&e.children.forEach(function(a){return v(a,f)});var s=m.beforeAppend&&m.beforeAppend(f);return s||d.appendChild(f),e.__htmlNode=f,f}function d(a){function e(a){"text"==a.type&&(c+=a.value||""),"img"==a.type&&f.push(a.src),a.children&&a.children.forEach(e)}var c="",f=[];return e(a),{text:c,imgs:f}}function j(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",a=p[e];if(!a){var f=n(e);a=_objectSpread({root:f},d(f)),p[e]=a}return a}function m(c){return new Promise(function(d){if(k[c])return d();var e=function(){k[c]=!0,d()};if(c.endsWith(".js")){var f=document.createElement("script");f.onload=e,f.src=c,document.head.appendChild(f)}else if(c.endsWith(".css")){var a=document.createElement("link");a.onload=e,a.type="text/css",a.rel="stylesheet",a.charset="utf-8",a.href=c,document.head.appendChild(a)}})}function o(c,a){Promise.all(a.asset.map(m)).then(function(){window.hljs&&c&&(window.hljs.configure({tabReplace:4}),_toConsumableArray(c.querySelectorAll("code.highlight")).forEach(function(a){window.hljs.highlightBlock(a)}))})}function f(a){return _objectSpread({asset:[]},a)}var G={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 /^!\[([^\]]*)\]\(([^)]+)\)/}},p={},k={},l=function(){function b(d,a){_classCallCheck(this,b),this.dom=d,this.config=a,this.prevRoot=null}return _createClass(b,[{key:"update",value:function(a){this.dom.classList.add("markdown");var d=j(a),b=u(this.prevRoot,d.root);this.prevRoot=d.root,s(b,this.dom);var c=f(this.config);c.useHighlight&&o(this.dom,c)}}]),b}();return a.Markdown=l,a.parser=n,a.trans=v,a.codeHighlight=o,a.getParseResult=j,a.markdown=function(a,d,c){a.innerHTML="",a.classList.add("markdown");var e=j(d);v(e.root,a),c=f(c),o(a,c)},a.markdownInfo=function(a){var e=j(a),b=e.root,c=_objectWithoutProperties(e,["root"]);return c},a}({}); |
{ | ||
"name": "lys-markdown-parser", | ||
"version": "3.10.0", | ||
"version": "3.11.0", | ||
"description": "js markdown parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -282,3 +282,4 @@ import { createAstNode } from './createAstNode.js'; | ||
root.push(node); | ||
index += matchTokens.length; | ||
index += matchTokens.length + 2; // 不渲染table结束空白行 | ||
}) | ||
@@ -321,3 +322,3 @@ ) { | ||
xx(info, root); | ||
index += matchTokens.length; | ||
index += matchTokens.length + 1; // list结束空白行只渲染一行 | ||
}) | ||
@@ -324,0 +325,0 @@ ) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
332627